mirror of
https://github.com/atom/atom.git
synced 2026-02-14 08:35:11 -05:00
Pass old/new buffer and screen positions to marker position observers
This is needed by the snippets package, which needs to know where the cursor was previously when it moves to decide whether to cancel the current snippet.
This commit is contained in:
@@ -36,9 +36,12 @@ class BufferMarker
|
||||
getTailPosition: -> @tailPosition
|
||||
|
||||
setHeadPosition: (headPosition, options={}) ->
|
||||
oldPosition = @headPosition
|
||||
@headPosition = Point.fromObject(headPosition)
|
||||
@headPosition = @buffer.clipPosition(@headPosition) if options.clip ? true
|
||||
observer(@headPosition, !!options.bufferChanged) for observer in @headPositionObservers
|
||||
newPosition = @headPosition
|
||||
bufferChanged = !!options.bufferChanged
|
||||
observer({oldPosition, newPosition, bufferChanged}) for observer in @headPositionObservers
|
||||
@headPosition
|
||||
|
||||
setTailPosition: (tailPosition, options={}) ->
|
||||
|
||||
@@ -12,10 +12,10 @@ class Cursor
|
||||
needsAutoscroll: null
|
||||
|
||||
constructor: ({@editSession, @marker}) ->
|
||||
@editSession.observeMarkerHeadScreenPosition @marker, (screenPosition, bufferChanged) =>
|
||||
@needsAutoscroll ?= @isLastCursor() and !bufferChanged
|
||||
@trigger 'moved', screenPosition
|
||||
@editSession.trigger 'cursor-moved', screenPosition
|
||||
@editSession.observeMarkerHeadScreenPosition @marker, (e) =>
|
||||
@needsAutoscroll ?= @isLastCursor() and !e.bufferChanged
|
||||
@trigger 'moved', e
|
||||
@editSession.trigger 'cursor-moved', e
|
||||
@needsAutoscroll = true
|
||||
|
||||
destroy: ->
|
||||
|
||||
@@ -372,9 +372,14 @@ class DisplayBuffer
|
||||
@markerScreenPositionObservers[id] ?= { head: [], tail: [] }
|
||||
@cacheMarkerScreenPositions(id) unless @markerScreenPositions[id]
|
||||
@markerScreenPositionObservers[id].head.push(callback)
|
||||
subscription = @buffer.observeMarkerHeadPosition id, (bufferPosition, bufferChanged) =>
|
||||
subscription = @buffer.observeMarkerHeadPosition id, (e) =>
|
||||
bufferChanged = e.bufferChanged
|
||||
oldBufferPosition = e.oldPosition
|
||||
newBufferPosition = e.newPosition
|
||||
oldScreenPosition = @markerScreenPositions[id].head
|
||||
@cacheMarkerScreenPositions(id)
|
||||
callback(@getMarkerHeadScreenPosition(id), bufferChanged)
|
||||
newScreenPosition = @getMarkerHeadScreenPosition(id)
|
||||
callback({ oldBufferPosition, newBufferPosition, oldScreenPosition, newScreenPosition, bufferChanged })
|
||||
|
||||
cancel: =>
|
||||
subscription.cancel()
|
||||
@@ -391,8 +396,13 @@ class DisplayBuffer
|
||||
for id, { head } of @markerScreenPositions
|
||||
currentHeadPosition = @getMarkerHeadScreenPosition(id)
|
||||
unless currentHeadPosition.isEqual(head)
|
||||
bufferChanged = false
|
||||
oldBufferPosition = newBufferPosition = @buffer.getMarkerHeadPosition(id)
|
||||
oldScreenPosition = @markerScreenPositions[id].head
|
||||
@cacheMarkerScreenPositions(id)
|
||||
observer(currentHeadPosition, false) for observer in @markerScreenPositionObservers[id].head
|
||||
newScreenPosition = @getMarkerHeadScreenPosition(id)
|
||||
for observer in @markerScreenPositionObservers[id].head
|
||||
observer({oldScreenPosition, newScreenPosition, oldBufferPosition, newBufferPosition, bufferChanged})
|
||||
|
||||
destroy: ->
|
||||
@tokenizedBuffer.destroy()
|
||||
|
||||
Reference in New Issue
Block a user