mirror of
https://github.com/atom/atom.git
synced 2026-02-14 00:25:08 -05:00
Add ability to cancel marker head position observations
This commit is contained in:
@@ -53,6 +53,8 @@ class BufferMarker
|
||||
|
||||
observeHeadPosition: (callback) ->
|
||||
@headPositionObservers.push(callback)
|
||||
cancel: =>
|
||||
_.remove(@headPositionObservers, callback)
|
||||
|
||||
tryToInvalidate: (oldRange) ->
|
||||
containsStart = oldRange.containsPoint(@getStartPosition(), exclusive: true)
|
||||
|
||||
@@ -355,10 +355,18 @@ class DisplayBuffer
|
||||
@markerScreenPositionObservers[id] ?= { head: [], tail: [] }
|
||||
@cacheMarkerScreenPositions(id) unless @markerScreenPositions[id]
|
||||
@markerScreenPositionObservers[id].head.push(callback)
|
||||
@buffer.observeMarkerHeadPosition id, (bufferPosition) =>
|
||||
subscription = @buffer.observeMarkerHeadPosition id, (bufferPosition) =>
|
||||
@cacheMarkerScreenPositions(id)
|
||||
callback(@screenPositionForBufferPosition(bufferPosition))
|
||||
|
||||
cancel: =>
|
||||
subscription.cancel()
|
||||
{ head, tail } = @markerScreenPositionObservers[id]
|
||||
_.remove(head, callback)
|
||||
unless head.length + tail.length
|
||||
delete @markerScreenPositionObservers[id]
|
||||
delete @markerScreenPositions[id]
|
||||
|
||||
cacheMarkerScreenPositions: (id) ->
|
||||
@markerScreenPositions[id] = { head: @getMarkerHeadScreenPosition(id), tail: @getMarkerTailScreenPosition }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user