mirror of
https://github.com/atom/atom.git
synced 2026-02-14 08:35:11 -05:00
WIP: Destroy nested tab stops when engulfed by a buffer change
Has 2 failing specs... There are still some issue with this code's interaction with the undo system. The tab stops will need to be or destroyed when certain changes are undone or redone.
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
Range = require 'range'
|
||||
EventEmitter = require 'event-emitter'
|
||||
Subscriber = require 'subscriber'
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class AnchorRange
|
||||
@@ -6,11 +9,14 @@ class AnchorRange
|
||||
end: null
|
||||
buffer: null
|
||||
editSession: null # optional
|
||||
destroyed: false
|
||||
|
||||
constructor: (bufferRange, @buffer, @editSession) ->
|
||||
bufferRange = Range.fromObject(bufferRange)
|
||||
@startAnchor = @buffer.addAnchorAtPosition(bufferRange.start, ignoreChangesStartingOnAnchor: true)
|
||||
@endAnchor = @buffer.addAnchorAtPosition(bufferRange.end)
|
||||
@subscribe @startAnchor, 'destroyed', => @destroy()
|
||||
@subscribe @endAnchor, 'destroyed', => @destroy()
|
||||
|
||||
getBufferRange: ->
|
||||
new Range(@startAnchor.getBufferPosition(), @endAnchor.getBufferPosition())
|
||||
@@ -22,7 +28,14 @@ class AnchorRange
|
||||
@getBufferRange().containsPoint(bufferPosition)
|
||||
|
||||
destroy: ->
|
||||
return if @destroyed
|
||||
@unsubscribe()
|
||||
@startAnchor.destroy()
|
||||
@endAnchor.destroy()
|
||||
@buffer.removeAnchorRange(this)
|
||||
@editSession?.removeAnchorRange(this)
|
||||
@destroyed = true
|
||||
@trigger 'destroyed'
|
||||
|
||||
_.extend(AnchorRange.prototype, EventEmitter)
|
||||
_.extend(AnchorRange.prototype, Subscriber)
|
||||
|
||||
@@ -10,6 +10,7 @@ class Anchor
|
||||
screenPosition: null
|
||||
ignoreChangesStartingOnAnchor: false
|
||||
strong: false
|
||||
destroyed: false
|
||||
|
||||
constructor: (@buffer, options = {}) ->
|
||||
{ @editSession, @ignoreChangesStartingOnAnchor, @strong } = options
|
||||
@@ -81,8 +82,10 @@ class Anchor
|
||||
@setScreenPosition(screenPosition, bufferChange: options.bufferChange, clip: false, assignBufferPosition: false, autoscroll: options.autoscroll)
|
||||
|
||||
destroy: ->
|
||||
return if @destroyed
|
||||
@buffer.removeAnchor(this)
|
||||
@editSession?.removeAnchor(this)
|
||||
@destroyed = true
|
||||
@trigger 'destroyed'
|
||||
|
||||
_.extend(Anchor.prototype, EventEmitter)
|
||||
|
||||
Reference in New Issue
Block a user