WIP: Start adding new anchorPoint API on edit session

These will replace anchors, but they won't be stored on the Buffer
at all. The API user will access them by a returned scalar id rather
than calling methods on the returned anchor object directly.
This commit is contained in:
Nathan Sobo
2013-01-29 18:21:56 -07:00
parent 3f50dbe1f8
commit 0ecfba3262
4 changed files with 149 additions and 17 deletions

View File

@@ -9,6 +9,7 @@ EventEmitter = require 'event-emitter'
Subscriber = require 'subscriber'
Range = require 'range'
AnchorRange = require 'anchor-range'
AnchorPoint = require 'anchor-point'
_ = require 'underscore'
fs = require 'fs'
@@ -40,6 +41,8 @@ class EditSession
@softTabs = @buffer.usesSoftTabs() ? softTabs ? true
@languageMode = new LanguageMode(this, @buffer.getExtension())
@displayBuffer = new DisplayBuffer(@buffer, { @languageMode, tabLength })
@nextAnchorPointId = 1
@anchorPointsById = {}
@anchors = []
@anchorRanges = []
@cursors = []
@@ -54,6 +57,7 @@ class EditSession
@preserveCursorPositionOnBufferReload()
@subscribe @displayBuffer, "changed", (e) =>
@updateAnchorPoints(e.bufferChange)
@refreshAnchorScreenPositions() unless e.bufferDelta
@trigger 'screen-lines-changed', e
@@ -351,6 +355,25 @@ class EditSession
pushOperation: (operation) ->
@buffer.pushOperation(operation, this)
updateAnchorPoints: (bufferChange) ->
return unless bufferChange
anchorPoint.handleBufferChange(bufferChange) for anchorPoint in @getAnchorPoints()
getAnchorPoints: ->
_.values(@anchorPointsById)
addAnchorPointAtBufferPosition: (bufferPosition, options) ->
id = @nextAnchorPointId++
params = _.extend({editSession: this, id, bufferPosition}, options)
@anchorPointsById[id] = new AnchorPoint(params)
id
getAnchorPointBufferPosition: (id) ->
@anchorPointsById[id]?.getBufferPosition()
removeAnchorPoint: (id) ->
delete @anchorPointsById[id]
getAnchors: ->
new Array(@anchors...)