Decorations can be flashed

This commit is contained in:
Ben Ogle
2014-07-02 18:36:29 -07:00
parent a56b5eef2f
commit bf33d96899
4 changed files with 54 additions and 13 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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