Tell marker head observers if a move was caused by a buffer change

This is used by cursor to only autoscroll when the marker head is
explicitly moved, so that passive movements caused by buffer insertions
don't trigger autoscrolling.
This commit is contained in:
Nathan Sobo
2013-02-02 16:17:14 -07:00
parent bd1a100d17
commit e53403718a
5 changed files with 19 additions and 15 deletions

View File

@@ -38,7 +38,7 @@ class BufferMarker
setHeadPosition: (headPosition, options={}) ->
@headPosition = Point.fromObject(headPosition)
@headPosition = @buffer.clipPosition(@headPosition) if options.clip ? true
observer(@headPosition) for observer in @headPositionObservers
observer(@headPosition, !!options.bufferChanged) for observer in @headPositionObservers
@headPosition
setTailPosition: (tailPosition, options={}) ->
@@ -81,8 +81,8 @@ class BufferMarker
[@id]
handleBufferChange: (bufferChange) ->
@setHeadPosition(@updatePosition(@headPosition, bufferChange, false), clip: false)
@setTailPosition(@updatePosition(@tailPosition, bufferChange, true), clip: false) if @tailPosition
@setHeadPosition(@updatePosition(@headPosition, bufferChange, false), clip: false, bufferChanged: true)
@setTailPosition(@updatePosition(@tailPosition, bufferChange, true), clip: false, bufferChanged: true) if @tailPosition
updatePosition: (position, bufferChange, isFirstPoint) ->
{ oldRange, newRange } = bufferChange

View File

@@ -12,8 +12,8 @@ class Cursor
needsAutoscroll: null
constructor: ({@editSession, @marker}) ->
@editSession.observeMarkerHeadScreenPosition @marker, (screenPosition) =>
@needsAutoscroll ?= @isLastCursor()
@editSession.observeMarkerHeadScreenPosition @marker, (screenPosition, bufferChanged) =>
@needsAutoscroll ?= @isLastCursor() and !bufferChanged
@trigger 'moved', screenPosition
@editSession.trigger 'cursor-moved', screenPosition
@needsAutoscroll = true

View File

@@ -372,9 +372,9 @@ class DisplayBuffer
@markerScreenPositionObservers[id] ?= { head: [], tail: [] }
@cacheMarkerScreenPositions(id) unless @markerScreenPositions[id]
@markerScreenPositionObservers[id].head.push(callback)
subscription = @buffer.observeMarkerHeadPosition id, (bufferPosition) =>
subscription = @buffer.observeMarkerHeadPosition id, (bufferPosition, bufferChanged) =>
@cacheMarkerScreenPositions(id)
callback(@getMarkerHeadScreenPosition(id))
callback(@getMarkerHeadScreenPosition(id), bufferChanged)
cancel: =>
subscription.cancel()
@@ -392,7 +392,7 @@ class DisplayBuffer
currentHeadPosition = @getMarkerHeadScreenPosition(id)
unless currentHeadPosition.isEqual(head)
@cacheMarkerScreenPositions(id)
observer(currentHeadPosition) for observer in @markerScreenPositionObservers[id].head
observer(currentHeadPosition, false) for observer in @markerScreenPositionObservers[id].head
destroy: ->
@tokenizedBuffer.destroy()