mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
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:
@@ -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...)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user