diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index 978ea0443..25d9d32e2 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -176,7 +176,6 @@ describe "Editor", -> editor.setMaxLineLength(50) fold = editor.createFold([[3, 52], [3, 56]]) fold.destroy() - # console.log editor.renderer.bufferRowsForScreenRows() expect(editor.gutter.find('.line-number:last').text()).toBe '13' it "adds a drop shadow when the horizontal scroller is scrolled to the right", -> @@ -196,6 +195,42 @@ describe "Editor", -> expect(editor.gutter).not.toHaveClass('drop-shadow') describe "cursor movement", -> + describe "move-to-top ", -> + it "moves cusor to the top of the buffer", -> + editor.setCursorScreenPosition [11,1] + editor.addCursorAtScreenPosition [12,0] + editor.trigger 'move-to-top' + expect(editor.getCursors().length).toBe 1 + expect(editor.getCursorBufferPosition()).toEqual [0,0] + + describe "move-to-bottom", -> + it "moves cusor to the bottom of the buffer", -> + editor.setCursorScreenPosition [0,0] + editor.addCursorAtScreenPosition [1,0] + editor.trigger 'move-to-bottom' + expect(editor.getCursors().length).toBe 1 + expect(editor.getCursorBufferPosition()).toEqual [12,2] + + describe "move-to-beginning-of-line", -> + it "moves cursor to the beginning of line", -> + editor.setCursorScreenPosition [0,5] + editor.addCursorAtScreenPosition [1,7] + editor.trigger 'move-to-beginning-of-line' + expect(editor.getCursors().length).toBe 2 + [cursor1, cursor2] = editor.getCursors() + expect(cursor1.getBufferPosition()).toEqual [0,0] + expect(cursor2.getBufferPosition()).toEqual [1,0] + + describe "move-to-end-of-line", -> + it "moves cursor to the end of line", -> + editor.setCursorScreenPosition [0,0] + editor.addCursorAtScreenPosition [1,0] + editor.trigger 'move-to-end-of-line' + expect(editor.getCursors().length).toBe 2 + [cursor1, cursor2] = editor.getCursors() + expect(cursor1.getBufferPosition()).toEqual [0,29] + expect(cursor2.getBufferPosition()).toEqual [1,30] + describe ".setCursorScreenPosition({row, column})", -> beforeEach -> editor.attachToDom() @@ -783,6 +818,26 @@ describe "Editor", -> expect(range.end).toEqual({row: 5, column: 27}) expect(editor.getCursorScreenPosition()).toEqual(row: 5, column: 27) + describe "select-to-top", -> + it "selects text from cusor position to the top of the buffer", -> + editor.setCursorScreenPosition [11,2] + editor.addCursorAtScreenPosition [10,0] + editor.trigger 'select-to-top' + expect(editor.getCursors().length).toBe 1 + expect(editor.getCursorBufferPosition()).toEqual [0,0] + expect(editor.getSelection().getBufferRange()).toEqual [[0,0], [11,2]] + expect(editor.getSelection().isReversed()).toBeTruthy() + + describe "select-to-bottom", -> + it "selects text from cusor position to the bottom of the buffer", -> + editor.setCursorScreenPosition [10,0] + editor.addCursorAtScreenPosition [9,3] + editor.trigger 'select-to-bottom' + expect(editor.getCursors().length).toBe 1 + expect(editor.getCursorBufferPosition()).toEqual [12,2] + expect(editor.getSelection().getBufferRange()).toEqual [[9,3], [12,2]] + expect(editor.getSelection().isReversed()).toBeFalsy() + describe "multiple cursors", -> it "places multiple cursor with meta-click", -> editor.attachToDom() diff --git a/src/atom/composite-cursor.coffee b/src/atom/composite-cursor.coffee index 4cf0084a9..c0d63f7c3 100644 --- a/src/atom/composite-cursor.coffee +++ b/src/atom/composite-cursor.coffee @@ -60,6 +60,18 @@ class CompositeCursor moveToNextWord: -> @modifyCursors (cursor) -> cursor.moveToNextWord() + moveToTop: -> + @modifyCursors (cursor) -> cursor.moveToTop() + + moveToBottom: -> + @modifyCursors (cursor) -> cursor.moveToBottom() + + moveToBeginningOfLine: -> + @modifyCursors (cursor) -> cursor.moveToBeginningOfLine() + + moveToEndOfLine: -> + @modifyCursors (cursor) -> cursor.moveToEndOfLine() + handleBufferChange: (e) -> @modifyCursors (cursor) -> cursor.handleBufferChange(e) diff --git a/src/atom/composite-selection.coffee b/src/atom/composite-selection.coffee index c3ecf983b..7d676da21 100644 --- a/src/atom/composite-selection.coffee +++ b/src/atom/composite-selection.coffee @@ -79,6 +79,14 @@ class CompositeSeleciton selection.selectDown() for selection in @getSelections() @mergeIntersectingSelections() + selectToTop: -> + selection.selectToTop() for selection in @getSelections() + @mergeIntersectingSelections reverse: true + + selectToBottom: -> + selection.selectToBottom() for selection in @getSelections() + @mergeIntersectingSelections() + setBufferRange: (bufferRange, options) -> @getLastSelection().setBufferRange(bufferRange, options) diff --git a/src/atom/cursor.coffee b/src/atom/cursor.coffee index 488bc6632..8fc5633b3 100644 --- a/src/atom/cursor.coffee +++ b/src/atom/cursor.coffee @@ -116,11 +116,11 @@ class Cursor extends View @setBufferPosition(nextPosition or @editor.getEofPosition()) - moveToLineEnd: -> + moveToEndOfLine: -> { row } = @getBufferPosition() @setBufferPosition({ row, column: @editor.buffer.lineForRow(row).length }) - moveToLineStart: -> + moveToBeginningOfLine: -> { row } = @getScreenPosition() @setScreenPosition({ row, column: 0 }) @@ -139,6 +139,12 @@ class Cursor extends View @setScreenPosition({row, column}) + moveToTop: -> + @setBufferPosition [0,0] + + moveToBottom: -> + @setBufferPosition @editor.getEofPosition() + moveLeftUntilMatch: (regex) -> row = @getScreenRow() column = @getScreenColumn() diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index f907566b3..63ff51e69 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -42,6 +42,7 @@ class Editor extends View requireStylesheet 'editor.css' requireStylesheet 'theme/twilight.css' require 'keybindings/emacs' + require 'keybindings/apple' @id = Editor.idCounter++ @editSessionsByBufferId = {} @@ -103,6 +104,13 @@ class Editor extends View @on 'split-down', => @splitDown() @on 'close', => @remove(); false + @on 'move-to-top', => @moveCursorToTop() + @on 'select-to-top', => @selectToTop() + @on 'move-to-bottom', => @moveCursorToBottom() + @on 'select-to-bottom', => @selectToBottom() + @on 'move-to-beginning-of-line', => @moveCursorToBeginningOfLine() + @on 'move-to-end-of-line', => @moveCursorToEndOfLine() + buildCursorAndSelection: -> @compositeSelection = new CompositeSelection(this) @compositeCursor = new CompositeCursor(this) @@ -357,6 +365,10 @@ class Editor extends View moveCursorRight: -> @compositeCursor.moveRight() moveCursorLeft: -> @compositeCursor.moveLeft() moveCursorToNextWord: -> @compositeCursor.moveToNextWord() + moveCursorToTop: -> @compositeCursor.moveToTop() + moveCursorToBottom: -> @compositeCursor.moveToBottom() + moveCursorToBeginningOfLine: -> @compositeCursor.moveToBeginningOfLine() + moveCursorToEndOfLine: -> @compositeCursor.moveToEndOfLine() setCursorScreenPosition: (position) -> @compositeCursor.setScreenPosition(position) getCursorScreenPosition: -> @compositeCursor.getCursor().getScreenPosition() setCursorBufferPosition: (position) -> @compositeCursor.setBufferPosition(position) @@ -372,6 +384,8 @@ class Editor extends View selectLeft: -> @compositeSelection.selectLeft() selectUp: -> @compositeSelection.selectUp() selectDown: -> @compositeSelection.selectDown() + selectToTop: -> @compositeSelection.selectToTop() + selectToBottom: -> @compositeSelection.selectToBottom() selectToScreenPosition: (position) -> @compositeSelection.selectToScreenPosition(position) clearSelections: -> @compositeSelection.clearSelections() diff --git a/src/atom/keybindings/apple.coffee b/src/atom/keybindings/apple.coffee new file mode 100644 index 000000000..c74b72c97 --- /dev/null +++ b/src/atom/keybindings/apple.coffee @@ -0,0 +1,7 @@ +window.keymap.bindKeys '.editor' + 'meta-up': 'move-to-top' + 'meta-shift-up': 'select-to-top' + 'meta-down': 'move-to-bottom' + 'meta-shift-down': 'select-to-bottom' + 'meta-right': 'move-to-end-of-line' + 'meta-left': 'move-to-beginning-of-line' \ No newline at end of file diff --git a/src/atom/selection.coffee b/src/atom/selection.coffee index 0ddabb989..2fa03a0e5 100644 --- a/src/atom/selection.coffee +++ b/src/atom/selection.coffee @@ -212,6 +212,14 @@ class Selection extends View @modifySelection => @cursor.moveDown() + selectToTop: -> + @modifySelection => + @cursor.moveToTop() + + selectToBottom: -> + @modifySelection => + @cursor.moveToBottom() + selectLeftUntilMatch: (regex) -> @modifySelection => @cursor.moveLeftUntilMatch(regex) @@ -220,12 +228,6 @@ class Selection extends View @modifySelection => @cursor.setScreenPosition(position) - moveCursorToLineEnd: -> - @cursor.moveToLineEnd() - - moveCursorToLineStart: -> - @cursor.moveToLineStart() - cut: (maintainPasteboard=false) -> @copy(maintainPasteboard) @delete()