mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
Decorations can be flashed
This commit is contained in:
@@ -30,3 +30,6 @@ class Decoration
|
||||
for key, value of decorationPattern
|
||||
return false if @params[key] != value
|
||||
true
|
||||
|
||||
flash: (klass, duration=500) ->
|
||||
@emit('flash', klass, duration)
|
||||
|
||||
@@ -19,22 +19,26 @@ HighlightComponent = React.createClass
|
||||
@renderMultiLineRegions()
|
||||
|
||||
componentDidMount: ->
|
||||
@startFlashAnimation() if @props.decoration.flash?
|
||||
{editor, decoration} = @props
|
||||
if decoration.id?
|
||||
@decoration = editor.decorationForId(decoration.id)
|
||||
@decoration.on 'flash', @startFlashAnimation
|
||||
|
||||
componentDidUpdate: ->
|
||||
@startFlashAnimation() if @props.decoration.flash?
|
||||
|
||||
startFlashAnimation: ->
|
||||
{flash} = @props.decoration
|
||||
componentWillUnmount: ->
|
||||
@decoration?.off 'flash', @startFlashAnimation
|
||||
|
||||
startFlashAnimation: (klass, duration) ->
|
||||
node = @getDOMNode()
|
||||
node.classList.remove(flash.class)
|
||||
node.classList.remove(klass)
|
||||
|
||||
requestAnimationFrame =>
|
||||
node.classList.add(flash.class)
|
||||
node.classList.add(klass)
|
||||
clearTimeout(@flashTimeoutId)
|
||||
removeFlashClass = -> node.classList.remove(flash.class)
|
||||
@flashTimeoutId = setTimeout(removeFlashClass, flash.duration ? 500)
|
||||
removeFlashClass = -> node.classList.remove(klass)
|
||||
@flashTimeoutId = setTimeout(removeFlashClass, duration)
|
||||
|
||||
renderSingleLineRegions: ->
|
||||
{startPixelPosition, endPixelPosition, lineHeightInPixels} = @props
|
||||
|
||||
@@ -12,12 +12,12 @@ HighlightsComponent = React.createClass
|
||||
@renderHighlights() if @isMounted()
|
||||
|
||||
renderHighlights: ->
|
||||
{highlightDecorations, lineHeightInPixels} = @props
|
||||
{editor, highlightDecorations, lineHeightInPixels} = @props
|
||||
|
||||
highlightComponents = []
|
||||
for markerId, {startPixelPosition, endPixelPosition, decorations} of highlightDecorations
|
||||
for decoration in decorations
|
||||
highlightComponents.push(HighlightComponent({key: "#{markerId}-#{decoration.class}", startPixelPosition, endPixelPosition, decoration, lineHeightInPixels}))
|
||||
highlightComponents.push(HighlightComponent({editor, key: "#{markerId}-#{decoration.class}", startPixelPosition, endPixelPosition, decoration, lineHeightInPixels}))
|
||||
|
||||
highlightComponents
|
||||
|
||||
|
||||
Reference in New Issue
Block a user