From 2df0b9fa194884efb8c27bcfe6c6e86ef31c21c8 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 30 Jan 2013 22:47:29 -0700 Subject: [PATCH] WIP: Start converting cursor and selection to be based on markers --- src/app/cursor.coffee | 31 ++++++++++--------------------- src/app/edit-session.coffee | 36 ++++++++++++++++++++++++++---------- src/app/editor.coffee | 4 ++-- 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/app/cursor.coffee b/src/app/cursor.coffee index fbdf78e8f..330b05464 100644 --- a/src/app/cursor.coffee +++ b/src/app/cursor.coffee @@ -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? diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index f9adc3f1b..d832e8e0f 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -434,6 +434,18 @@ class EditSession getAnchorRanges: -> new Array(@anchorRanges...) + markScreenPosition: (args...) -> + @displayBuffer.markScreenPosition(args...) + + markBufferPosition: (args...) -> + @displayBuffer.markBufferPosition(args...) + + getMarkerBufferRange: (marker) -> + @displayBuffer.getMarkerBufferRange(marker) + + getMarkerScreenRange: (marker) -> + @displayBuffer.getMarkerScreenRange(marker) + addAnchor: (options={}) -> anchor = @buffer.addAnchor(_.extend({editSession: this}, options)) @anchors.push(anchor) @@ -470,31 +482,35 @@ class EditSession _.last(@cursors) addCursorAtScreenPosition: (screenPosition) -> - @addCursor(new Cursor(editSession: this, screenPosition: screenPosition)) + marker = @markScreenPosition(screenPosition, stayValid: true) + @addSelection(marker).cursor addCursorAtBufferPosition: (bufferPosition) -> - @addCursor(new Cursor(editSession: this, bufferPosition: bufferPosition)) + marker = @markBufferPosition(screenPosition, stayValid: true) + @addSelection(marker).cursor - addCursor: (cursor=new Cursor(editSession: this, screenPosition: [0,0])) -> + addCursor: (marker) -> + cursor = new Cursor(editSession: this, marker: marker) @cursors.push(cursor) @trigger 'cursor-added', cursor - @addSelectionForCursor(cursor) cursor removeCursor: (cursor) -> _.remove(@cursors, cursor) - addSelectionForCursor: (cursor) -> - selection = new Selection(editSession: this, cursor: cursor) + addSelection: (marker, options={}) -> + unless options.preserveFolds + @destroyFoldsIntersectingBufferRange(@getMarkerBufferRange(marker)) + cursor = @addCursor(marker) + selection = new Selection({editSession: this, marker, cursor}) @selections.push(selection) + @mergeIntersectingSelections() @trigger 'selection-added', selection selection addSelectionForBufferRange: (bufferRange, options={}) -> - bufferRange = Range.fromObject(bufferRange) - @destroyFoldsIntersectingBufferRange(bufferRange) unless options.preserveFolds - @addCursor().selection.setBufferRange(bufferRange, options) - @mergeIntersectingSelections() + marker = @markBufferRange(bufferRange, _.defaults({stayValid: true}, options)) + @addSelection(marker) setSelectedBufferRange: (bufferRange, options) -> @setSelectedBufferRanges([bufferRange], options) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index fcc9a9409..97049878d 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -1086,7 +1086,7 @@ class Editor extends View if fold = screenLine.fold lineAttributes = { class: 'fold line', 'fold-id': fold.id } else - lineAttributes = { class: 'line' } + lineAttributes = { class: 'line' } attributePairs = [] attributePairs.push "#{attributeName}=\"#{value}\"" for attributeName, value of lineAttributes @@ -1117,7 +1117,7 @@ class Editor extends View if invisibles.eol line.push("") - line.push("") if fold + # line.push("") if fold line.push('') line.join('')