diff --git a/src/app/cursor-view.coffee b/src/app/cursor-view.coffee index 4d72e07c8..d1b009773 100644 --- a/src/app/cursor-view.coffee +++ b/src/app/cursor-view.coffee @@ -29,8 +29,6 @@ class CursorView extends View handleBufferChange: (e) -> @cursor.handleBufferChange(e) - # @anchor.handleBufferChange(e) - # @refreshScreenPosition() @trigger 'cursor-move', bufferChange: true remove: -> @@ -44,10 +42,6 @@ class CursorView extends View setBufferPosition: (bufferPosition, options={}) -> @cursor.setBufferPosition(bufferPosition, options) - # @anchor.setBufferPosition(bufferPosition, options) - # @refreshScreenPosition() - # @trigger 'cursor-move', bufferChange: false - # @clearSelection() getScreenPosition: -> @anchor.getScreenPosition() @@ -152,21 +146,6 @@ class CursorView extends View newPosition = [position.row, 0] if newPosition.isEqual(position) @setBufferPosition(newPosition) - moveRight: -> - { row, column } = @getScreenPosition() - @setScreenPosition([row, column + 1], skipAtomicTokens: true, wrapBeyondNewlines: true, wrapAtSoftNewlines: true) - - moveLeft: -> - { row, column } = @getScreenPosition() - [row, column] = if column > 0 then [row, column - 1] else [row - 1, Infinity] - @setScreenPosition({row, column}) - - moveToTop: -> - @setBufferPosition [0,0] - - moveToBottom: -> - @setBufferPosition @editor.getEofPosition() - updateAppearance: -> screenPosition = @getScreenPosition() pixelPosition = @editor.pixelPositionForScreenPosition(screenPosition) diff --git a/src/app/cursor.coffee b/src/app/cursor.coffee index e60aa81e8..9cce5fd32 100644 --- a/src/app/cursor.coffee +++ b/src/app/cursor.coffee @@ -46,6 +46,21 @@ class Cursor @setScreenPosition({row: row + 1, column: column}) @goalColumn = column + moveLeft: -> + { row, column } = @getScreenPosition() + [row, column] = if column > 0 then [row, column - 1] else [row - 1, Infinity] + @setScreenPosition({row, column}) + + moveRight: -> + { row, column } = @getScreenPosition() + @setScreenPosition([row, column + 1], skipAtomicTokens: true, wrapBeyondNewlines: true, wrapAtSoftNewlines: true) + + moveToTop: -> + @setBufferPosition([0,0]) + + moveToBottom: -> + @setBufferPosition(@editSession.getEofBufferPosition()) + destroy: -> @editSession.removeCursor(this) @trigger 'destroy' diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 700f868d8..57f6e2c99 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -51,6 +51,9 @@ class EditSession clipScreenPosition: (screenPosition, options) -> @renderer.clipScreenPosition(screenPosition, options) + getEofBufferPosition: -> + @buffer.getEofPosition() + getCursors: -> @cursors addCursorAtScreenPosition: (screenPosition) -> @@ -88,6 +91,18 @@ class EditSession moveCursorDown: -> @moveCursors (cursor) -> cursor.moveDown() + moveCursorLeft: -> + @moveCursors (cursor) -> cursor.moveLeft() + + moveCursorRight: -> + @moveCursors (cursor) -> cursor.moveRight() + + moveCursorToTop: -> + @moveCursors (cursor) -> cursor.moveToTop() + + moveCursorToBottom: -> + @moveCursors (cursor) -> cursor.moveToBottom() + moveCursors: (fn) -> fn(cursor) for cursor in @getCursors() @mergeCursors() diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 85bb41ecf..049d68b19 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -642,13 +642,13 @@ class Editor extends View getCursors: -> @compositeCursor.getCursors() moveCursorUp: -> @activeEditSession.moveCursorUp() moveCursorDown: -> @activeEditSession.moveCursorDown() - moveCursorRight: -> @compositeCursor.moveRight() - moveCursorLeft: -> @compositeCursor.moveLeft() + moveCursorLeft: -> @activeEditSession.moveCursorLeft() + moveCursorRight: -> @activeEditSession.moveCursorRight() moveCursorToNextWord: -> @compositeCursor.moveToNextWord() moveCursorToBeginningOfWord: -> @compositeCursor.moveToBeginningOfWord() moveCursorToEndOfWord: -> @compositeCursor.moveToEndOfWord() - moveCursorToTop: -> @compositeCursor.moveToTop() - moveCursorToBottom: -> @compositeCursor.moveToBottom() + moveCursorToTop: -> @activeEditSession.moveCursorToTop() + moveCursorToBottom: -> @activeEditSession.moveCursorToBottom() moveCursorToBeginningOfLine: -> @compositeCursor.moveToBeginningOfLine() moveCursorToFirstCharacterOfLine: -> @compositeCursor.moveToFirstCharacterOfLine() moveCursorToEndOfLine: -> @compositeCursor.moveToEndOfLine() diff --git a/src/app/selection.coffee b/src/app/selection.coffee index 61267b932..4e3a48bc7 100644 --- a/src/app/selection.coffee +++ b/src/app/selection.coffee @@ -202,10 +202,10 @@ class Selection extends View @modifySelection => @cursor.setScreenPosition(position) selectRight: -> - @modifySelection => @cursor.moveRight() + @modifySelection => @cursor.cursor.moveRight() selectLeft: -> - @modifySelection => @cursor.moveLeft() + @modifySelection => @cursor.cursor.moveLeft() selectUp: -> @modifySelection => @cursor.cursor.moveUp() @@ -214,10 +214,10 @@ class Selection extends View @modifySelection => @cursor.cursor.moveDown() selectToTop: -> - @modifySelection => @cursor.moveToTop() + @modifySelection => @cursor.cursor.moveToTop() selectToBottom: -> - @modifySelection => @cursor.moveToBottom() + @modifySelection => @cursor.cursor.moveToBottom() selectAll: -> @setBufferRange(@editor.buffer.getRange())