mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Fix decorations flashing more than once
When, after flashing a decoration, the decorated range moved, Atom was showing an additional flash, even if the previous one had already been consumed. This bug originated in `HighlightsComponent`, where we maintained state about a certain highlight's flash count. The problem with this approach, however, is that highlight objects in the component are very volatile, and we could even have more than one for a single decoration (i.e. when such decoration spans multiple tiles). To fix this, we'll now maintain some additional state in `TextEditorPresenter`, which will set a `needsFlash` attribute on the highlight state objects, thereby preventing `HighlightsComponent` from showing the flash animation more than once when the decorated range changes.
This commit is contained in:
@@ -97,24 +97,23 @@ class HighlightsComponent
|
||||
|
||||
flashHighlightNodeIfRequested: (id, newHighlightState) ->
|
||||
oldHighlightState = @oldState[id]
|
||||
return unless newHighlightState.flashCount > oldHighlightState.flashCount
|
||||
if newHighlightState.needsFlash and oldHighlightState.flashCount isnt newHighlightState.flashCount
|
||||
highlightNode = @highlightNodesById[id]
|
||||
|
||||
highlightNode = @highlightNodesById[id]
|
||||
addFlashClass = =>
|
||||
highlightNode.classList.add(newHighlightState.flashClass)
|
||||
oldHighlightState.flashClass = newHighlightState.flashClass
|
||||
@flashTimeoutId = setTimeout(removeFlashClass, newHighlightState.flashDuration)
|
||||
|
||||
addFlashClass = =>
|
||||
highlightNode.classList.add(newHighlightState.flashClass)
|
||||
oldHighlightState.flashClass = newHighlightState.flashClass
|
||||
@flashTimeoutId = setTimeout(removeFlashClass, newHighlightState.flashDuration)
|
||||
removeFlashClass = =>
|
||||
highlightNode.classList.remove(oldHighlightState.flashClass)
|
||||
oldHighlightState.flashClass = null
|
||||
clearTimeout(@flashTimeoutId)
|
||||
|
||||
removeFlashClass = =>
|
||||
highlightNode.classList.remove(oldHighlightState.flashClass)
|
||||
oldHighlightState.flashClass = null
|
||||
clearTimeout(@flashTimeoutId)
|
||||
if oldHighlightState.flashClass?
|
||||
removeFlashClass()
|
||||
requestAnimationFrame(addFlashClass)
|
||||
else
|
||||
addFlashClass()
|
||||
|
||||
if oldHighlightState.flashClass?
|
||||
removeFlashClass()
|
||||
requestAnimationFrame(addFlashClass)
|
||||
else
|
||||
addFlashClass()
|
||||
|
||||
oldHighlightState.flashCount = newHighlightState.flashCount
|
||||
oldHighlightState.flashCount = newHighlightState.flashCount
|
||||
|
||||
Reference in New Issue
Block a user