mirror of
https://github.com/atom/atom.git
synced 2026-01-22 13:28:01 -05:00
Flash works for selections
This commit is contained in:
@@ -743,6 +743,19 @@ describe "EditorComponent", ->
|
||||
expect(selectionNode.offsetTop).toBe editor.getLineHeightInPixels()
|
||||
expect(selectionNode.offsetLeft).toBe editor.pixelPositionForScreenPosition([1, 6]).left
|
||||
|
||||
it "will flash the selection when flash:true is passed to editor::setSelectedBufferRange", ->
|
||||
editor.setSelectedBufferRange([[1, 6], [1, 10]], flash: true)
|
||||
runSetImmediateCallbacks()
|
||||
selectionNode = node.querySelector('.selection')
|
||||
expect(selectionNode.classList.contains('highlighted')).toBe true
|
||||
|
||||
advanceClock 500
|
||||
expect(selectionNode.classList.contains('highlighted')).toBe false
|
||||
|
||||
editor.setSelectedBufferRange([[1, 5], [1, 7]], flash: true)
|
||||
runSetImmediateCallbacks()
|
||||
expect(selectionNode.classList.contains('highlighted')).toBe true
|
||||
|
||||
describe "line decoration rendering", ->
|
||||
[marker, decoration] = []
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ class Decoration
|
||||
constructor: (@marker, @params) ->
|
||||
@id = nextId()
|
||||
@params.id = @id
|
||||
@flashQueue = null
|
||||
|
||||
getParams: ->
|
||||
@params
|
||||
@@ -32,4 +33,11 @@ class Decoration
|
||||
true
|
||||
|
||||
flash: (klass, duration=500) ->
|
||||
@emit('flash', klass, duration)
|
||||
flashObject = {class: klass, duration}
|
||||
@flashQueue ?= []
|
||||
@flashQueue.push(flashObject)
|
||||
@emit('flash')
|
||||
|
||||
consumeNextFlash: ->
|
||||
return @flashQueue.shift() if @flashQueue?.length > 0
|
||||
null
|
||||
|
||||
@@ -23,22 +23,22 @@ HighlightComponent = React.createClass
|
||||
if decoration.id?
|
||||
@decoration = editor.decorationForId(decoration.id)
|
||||
@decoration.on 'flash', @startFlashAnimation
|
||||
|
||||
componentDidUpdate: ->
|
||||
@startFlashAnimation() if @props.decoration.flash?
|
||||
@startFlashAnimation()
|
||||
|
||||
componentWillUnmount: ->
|
||||
@decoration?.off 'flash', @startFlashAnimation
|
||||
|
||||
startFlashAnimation: (klass, duration) ->
|
||||
startFlashAnimation: ->
|
||||
return unless flash = @decoration.consumeNextFlash()
|
||||
|
||||
node = @getDOMNode()
|
||||
node.classList.remove(klass)
|
||||
node.classList.remove(flash.class)
|
||||
|
||||
requestAnimationFrame =>
|
||||
node.classList.add(klass)
|
||||
node.classList.add(flash.class)
|
||||
clearTimeout(@flashTimeoutId)
|
||||
removeFlashClass = -> node.classList.remove(klass)
|
||||
@flashTimeoutId = setTimeout(removeFlashClass, duration)
|
||||
removeFlashClass = -> node.classList.remove(flash.class)
|
||||
@flashTimeoutId = setTimeout(removeFlashClass, flash.duration)
|
||||
|
||||
renderSingleLineRegions: ->
|
||||
{startPixelPosition, endPixelPosition, lineHeightInPixels} = @props
|
||||
|
||||
@@ -78,9 +78,12 @@ class Selection extends Model
|
||||
options.reversed ?= @isReversed()
|
||||
@editor.destroyFoldsIntersectingBufferRange(bufferRange) unless options.preserveFolds
|
||||
@modifySelection =>
|
||||
needsFlash = options.flash
|
||||
delete options.flash if options.flash?
|
||||
@cursor.needsAutoscroll = false if @needsAutoscroll?
|
||||
@marker.setBufferRange(bufferRange, options)
|
||||
@autoscroll() if @needsAutoscroll and @editor.manageScrollPosition
|
||||
@decoration.flash('highlighted', 500) if needsFlash
|
||||
|
||||
# Public: Returns the starting and ending buffer rows the selection is
|
||||
# highlighting.
|
||||
|
||||
Reference in New Issue
Block a user