WIP: Start converting cursor and selection to be based on markers

This commit is contained in:
Nathan Sobo
2013-01-30 22:47:29 -07:00
parent 074c1815d0
commit 2df0b9fa19
3 changed files with 38 additions and 33 deletions

View File

@@ -1,6 +1,5 @@
Point = require 'point'
Range = require 'range'
Anchor = require 'anchor'
EventEmitter = require 'event-emitter'
_ = require 'underscore'
@@ -12,19 +11,15 @@ class Cursor
visible: true
needsAutoscroll: null
constructor: ({@editSession, screenPosition, bufferPosition}) ->
@anchor = @editSession.addAnchor(strong: true)
@anchor.on 'moved', (e) =>
@needsAutoscroll ?= @isLastCursor()
@trigger 'moved', e
@editSession.trigger 'cursor-moved', e
@setScreenPosition(screenPosition) if screenPosition
@setBufferPosition(bufferPosition) if bufferPosition
constructor: ({@editSession, @marker}) ->
# @editSession.observeMarkerHeadScreenPosition @marker, (screenPosition) ->
# @needsAutoscroll ?= @isLastCursor()
# @trigger 'moved', e
# @editSession.trigger 'cursor-moved', e
@needsAutoscroll = true
destroy: ->
@anchor.destroy()
@editSession.destroyMarker(@marker)
@editSession.removeCursor(this)
@trigger 'destroyed'
@@ -32,22 +27,19 @@ class Cursor
@goalColumn = null
@clearSelection()
@needsAutoscroll = (options.autoscroll ? true) and @isLastCursor()
@anchor.setScreenPosition(screenPosition, options)
@editSession.setMarkerHeadScreenPosition(@marker, screenPosition, options)
getScreenPosition: ->
@anchor.getScreenPosition()
getScreenRow: ->
@anchor.getScreenRow()
@editSession.getMarkerHeadScreenPosition(@marker)
setBufferPosition: (bufferPosition, options={}) ->
@goalColumn = null
@clearSelection()
@needsAutoscroll = options.autoscroll ? @isLastCursor()
@anchor.setBufferPosition(bufferPosition, options)
@editSession.setMarkerHeadBufferPosition(@marker, screenPosition, options)
getBufferPosition: ->
@anchor.getBufferPosition()
@editSession.getMarkerHeadBufferPosition(@marker)
setVisible: (visible) ->
if @visible != visible
@@ -91,9 +83,6 @@ class Cursor
getCurrentBufferLine: ->
@editSession.lineForBufferRow(@getBufferRow())
refreshScreenPosition: ->
@anchor.refreshScreenPosition()
moveUp: (rowCount = 1) ->
{ row, column } = @getScreenPosition()
column = @goalColumn if @goalColumn?