Move anchor points to buffer; restore invalidated points on undo

This commit is contained in:
Nathan Sobo
2013-01-30 12:23:42 -07:00
parent 6c7b93872c
commit 30909a8e8f
6 changed files with 124 additions and 136 deletions

View File

@@ -8,6 +8,7 @@ UndoManager = require 'undo-manager'
BufferChangeOperation = require 'buffer-change-operation'
Anchor = require 'anchor'
AnchorRange = require 'anchor-range'
AnchorPoint = require 'anchor-point'
module.exports =
class Buffer
@@ -21,12 +22,17 @@ class Buffer
lines: null
lineEndings: null
file: null
validAnchorPointsById: null
invalidAnchorPointsById: null
anchors: null
anchorRanges: null
refcount: 0
constructor: (path, @project) ->
@id = @constructor.idCounter++
@nextAnchorPointId = 1
@validAnchorPointsById = {}
@invalidAnchorPointsById = {}
@anchors = []
@anchorRanges = []
@lines = ['']
@@ -258,6 +264,22 @@ class Buffer
isEmpty: -> @lines.length is 1 and @lines[0].length is 0
updateAnchorPoints: (bufferChange) ->
return unless bufferChange
anchorPoint.handleBufferChange(bufferChange) for anchorPoint in @getAnchorPoints()
getAnchorPoints: ->
_.values(@validAnchorPointsById)
addAnchorPoint: (position, options) ->
id = @nextAnchorPointId++
params = _.extend({buffer: this, id, position}, options)
@validAnchorPointsById[id] = new AnchorPoint(params)
id
getAnchorPoint: (id) ->
@validAnchorPointsById[id]?.getPosition()
getAnchors: -> new Array(@anchors...)
addAnchor: (options) ->