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:
Nathan Sobo
2013-02-02 18:00:35 -07:00
parent e25d83ccbc
commit bd96db781e
5 changed files with 72 additions and 17 deletions

View File

@@ -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={}) ->

View File

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

View File

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