mirror of
https://github.com/atom/atom.git
synced 2026-02-14 00:25:08 -05:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user