From 2d858251269c2755a99e60053b4c769f3b2d855a Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Wed, 28 Mar 2012 15:07:44 -0700 Subject: [PATCH] Add select-to-beginning-of-line and select-to-end-of-line --- spec/atom/editor-spec.coffee | 34 +++++++++++++++++++++++++++++ src/atom/composite-selection.coffee | 8 +++++++ src/atom/editor.coffee | 8 +++++-- src/atom/selection.coffee | 8 +++++++ 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index 8f82e2aea..60ea57727 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -863,6 +863,40 @@ describe "Editor", -> expect(editor.getSelection().getBufferRange()).toEqual [[9,3], [12,2]] expect(editor.getSelection().isReversed()).toBeFalsy() + describe "select-to-beginning-of-line", -> + it "selects text from cusor position to end of line", -> + editor.setCursorScreenPosition [12,2] + editor.addCursorAtScreenPosition [11,3] + editor.trigger 'select-to-beginning-of-line' + expect(editor.getCursors().length).toBe 2 + [cursor1, cursor2] = editor.getCursors() + expect(cursor1.getBufferPosition()).toEqual [12,0] + expect(cursor2.getBufferPosition()).toEqual [11,0] + + expect(editor.getSelections().length).toBe 2 + [selection1, selection2] = editor.getSelections() + expect(selection1.getBufferRange()).toEqual [[12,0], [12,2]] + expect(selection1.isReversed()).toBeTruthy() + expect(selection2.getBufferRange()).toEqual [[11,0], [11,3]] + expect(selection2.isReversed()).toBeTruthy() + + describe "select-to-end-of-line", -> + it "selects text from cusor position to end of line", -> + editor.setCursorScreenPosition [12,0] + editor.addCursorAtScreenPosition [11,3] + editor.trigger 'select-to-end-of-line' + expect(editor.getCursors().length).toBe 2 + [cursor1, cursor2] = editor.getCursors() + expect(cursor1.getBufferPosition()).toEqual [12,2] + expect(cursor2.getBufferPosition()).toEqual [11,44] + + expect(editor.getSelections().length).toBe 2 + [selection1, selection2] = editor.getSelections() + expect(selection1.getBufferRange()).toEqual [[12,0], [12,2]] + expect(selection1.isReversed()).toBeFalsy() + expect(selection2.getBufferRange()).toEqual [[11,3], [11,44]] + expect(selection2.isReversed()).toBeFalsy() + describe "multiple cursors", -> it "places multiple cursor with meta-click", -> editor.attachToDom() diff --git a/src/atom/composite-selection.coffee b/src/atom/composite-selection.coffee index 7d676da21..11b07df17 100644 --- a/src/atom/composite-selection.coffee +++ b/src/atom/composite-selection.coffee @@ -87,6 +87,14 @@ class CompositeSeleciton selection.selectToBottom() for selection in @getSelections() @mergeIntersectingSelections() + selectToBeginningOfLine: -> + selection.selectToBeginningOfLine() for selection in @getSelections() + @mergeIntersectingSelections reverse: true + + selectToEndOfLine: -> + selection.selectToEndOfLine() for selection in @getSelections() + @mergeIntersectingSelections() + setBufferRange: (bufferRange, options) -> @getLastSelection().setBufferRange(bufferRange, options) diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index d94d13a44..9653fa4bf 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -106,12 +106,14 @@ class Editor extends View @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() @on 'move-to-first-character-of-line', => @moveCursorToFirstCharacterOfLine() + @on 'select-to-top', => @selectToTop() + @on 'select-to-bottom', => @selectToBottom() + @on 'select-to-end-of-line', => @selectToEndOfLine() + @on 'select-to-beginning-of-line', => @selectToBeginningOfLine() buildCursorAndSelection: -> @compositeSelection = new CompositeSelection(this) @@ -390,6 +392,8 @@ class Editor extends View selectDown: -> @compositeSelection.selectDown() selectToTop: -> @compositeSelection.selectToTop() selectToBottom: -> @compositeSelection.selectToBottom() + selectToEndOfLine: -> @compositeSelection.selectToEndOfLine() + selectToBeginningOfLine: -> @compositeSelection.selectToBeginningOfLine() selectToScreenPosition: (position) -> @compositeSelection.selectToScreenPosition(position) clearSelections: -> @compositeSelection.clearSelections() diff --git a/src/atom/selection.coffee b/src/atom/selection.coffee index 2fa03a0e5..6cca582d8 100644 --- a/src/atom/selection.coffee +++ b/src/atom/selection.coffee @@ -228,6 +228,14 @@ class Selection extends View @modifySelection => @cursor.setScreenPosition(position) + selectToBeginningOfLine: -> + @modifySelection => + @cursor.moveToBeginningOfLine() + + selectToEndOfLine: -> + @modifySelection => + @cursor.moveToEndOfLine() + cut: (maintainPasteboard=false) -> @copy(maintainPasteboard) @delete()