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:
Nathan Sobo
2013-01-07 21:46:44 -07:00
parent 62d7273069
commit 314e3da8bc
5 changed files with 38 additions and 8 deletions

View File

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

View File

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