Finish converting cursors to use markers.

The model layer works at least… haven't tested the view. Will test out
the view once I get the selection model working.
This commit is contained in:
Nathan Sobo
2013-01-31 15:52:28 -07:00
parent ec521b3fd3
commit 628701fd3a
8 changed files with 96 additions and 17 deletions

View File

@@ -95,8 +95,8 @@ class BufferChangeOperation
restoreMarkers: (markersToRestore) ->
for [id, previousRange] in markersToRestore
if existingMarker = @buffer.validMarkers[id]
existingMarker.setRange(previousRange)
else
@buffer.validMarkers[id] = @buffer.invalidMarkers[id]
if validMarker = @buffer.validMarkers[id]
validMarker.setRange(previousRange)
else if invalidMarker = @buffer.invalidMarkers[id]
@buffer.validMarkers[id] = invalidMarker

View File

@@ -283,6 +283,10 @@ class Buffer
markPosition: (position, options) ->
@markRange([position, position], _.defaults({noTail: true}, options))
destroyMarker: (id) ->
delete @validMarkers[id]
delete @invalidMarkers[id]
getMarkerPosition: (args...) ->
@getMarkerHeadPosition(args...)

View File

@@ -12,10 +12,10 @@ class Cursor
needsAutoscroll: null
constructor: ({@editSession, @marker}) ->
# @editSession.observeMarkerHeadScreenPosition @marker, (screenPosition) ->
# @needsAutoscroll ?= @isLastCursor()
# @trigger 'moved', e
# @editSession.trigger 'cursor-moved', e
@editSession.observeMarkerHeadScreenPosition @marker, (screenPosition) =>
@needsAutoscroll ?= @isLastCursor()
@trigger 'moved', screenPosition
@editSession.trigger 'cursor-moved', screenPosition
@needsAutoscroll = true
destroy: ->
@@ -36,7 +36,7 @@ class Cursor
@goalColumn = null
@clearSelection()
@needsAutoscroll = options.autoscroll ? @isLastCursor()
@editSession.setMarkerHeadBufferPosition(@marker, screenPosition, options)
@editSession.setMarkerHeadBufferPosition(@marker, bufferPosition, options)
getBufferPosition: ->
@editSession.getMarkerHeadBufferPosition(@marker)

View File

@@ -312,6 +312,11 @@ class DisplayBuffer
markBufferPosition: (bufferPosition) ->
@buffer.markPosition(bufferPosition)
destroyMarker: (id) ->
@buffer.destroyMarker(id)
delete @markerScreenPositionObservers[id]
delete @markerScreenPositions[id]
getMarkerScreenRange: (id) ->
@screenRangeForBufferRange(@getMarkerBufferRange(id))
@@ -328,6 +333,7 @@ class DisplayBuffer
@screenPositionForBufferPosition(@getMarkerHeadBufferPosition(id))
setMarkerHeadScreenPosition: (id, screenPosition, options) ->
screenPosition = @clipScreenPosition(screenPosition, options)
@setMarkerHeadBufferPosition(id, @bufferPositionForScreenPosition(screenPosition, options))
getMarkerHeadBufferPosition: (id) ->
@@ -340,6 +346,7 @@ class DisplayBuffer
@screenPositionForBufferPosition(@getMarkerTailBufferPosition(id))
setMarkerTailScreenPosition: (id, screenPosition, options) ->
screenPosition = @clipScreenPosition(screenPosition, options)
@setMarkerTailBufferPosition(id, @bufferPositionForScreenPosition(screenPosition, options))
getMarkerTailBufferPosition: (id) ->

View File

@@ -440,21 +440,48 @@ class EditSession
markBufferPosition: (args...) ->
@displayBuffer.markBufferPosition(args...)
destroyMarker: (args...) ->
@displayBuffer.destroyMarker(args...)
getMarkerBufferRange: (args...) ->
@displayBuffer.getMarkerBufferRange(args...)
getMarkerScreenRange: (args...) ->
@displayBuffer.getMarkerScreenRange(args...)
getMarkerScreenPosition: (args...) ->
@displayBuffer.getMarkerScreenPosition(args...)
getMarkerBufferPosition: (args...) ->
@displayBuffer.getMarkerBufferPosition(args...)
getMarkerHeadScreenPosition: (args...) ->
@displayBuffer.getMarkerHeadScreenPosition(args...)
setMarkerHeadScreenPosition: (args...) ->
@displayBuffer.setMarkerHeadScreenPosition(args...)
getMarkerHeadBufferPosition: (args...) ->
@displayBuffer.getMarkerHeadBufferPosition(args...)
setMarkerHeadBufferPosition: (args...) ->
@displayBuffer.setMarkerHeadBufferPosition(args...)
getMarkerTailScreenPosition: (args...) ->
@displayBuffer.getMarkerTailScreenPosition(args...)
setMarkerTailScreenPosition: (args...) ->
@displayBuffer.setMarkerTailScreenPosition(args...)
getMarkerTailBufferPosition: (args...) ->
@displayBuffer.getMarkerTailBufferPosition(args...)
setMarkerTailBufferPosition: (args...) ->
@displayBuffer.setMarkerTailBufferPosition(args...)
observeMarkerHeadScreenPosition: (args...) ->
@displayBuffer.observeMarkerHeadScreenPosition(args...)
addAnchor: (options={}) ->
anchor = @buffer.addAnchor(_.extend({editSession: this}, options))
@anchors.push(anchor)
@@ -495,7 +522,7 @@ class EditSession
@addSelection(marker).cursor
addCursorAtBufferPosition: (bufferPosition) ->
marker = @markBufferPosition(screenPosition, stayValid: true)
marker = @markBufferPosition(bufferPosition, stayValid: true)
@addSelection(marker).cursor
addCursor: (marker) ->