From fe4c4e9751175f267d2d7f953aa8c925bf62a7cf Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 18 Jul 2013 17:29:42 -0700 Subject: [PATCH] Add selectToFirstCharacterOfLine to editSession --- spec/app/edit-session-spec.coffee | 25 +++++++++++++++++++++++++ src/app/edit-session.coffee | 4 ++++ src/app/selection.coffee | 4 ++++ 3 files changed, 33 insertions(+) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 47f8ac23d..ebe1cb328 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -703,6 +703,31 @@ describe "EditSession", -> editSession.selectWord() expect(editSession.getSelectedBufferRange()).toEqual [[12, 2], [12, 6]] + describe ".selectToFirstCharacterOfLine()", -> + it "moves to the first character of the current line or the beginning of the line if it's already on the first character", -> + editSession.setCursorScreenPosition [0,5] + editSession.addCursorAtScreenPosition [1,7] + + editSession.selectToFirstCharacterOfLine() + + [cursor1, cursor2] = editSession.getCursors() + expect(cursor1.getBufferPosition()).toEqual [0,0] + expect(cursor2.getBufferPosition()).toEqual [1,2] + + expect(editSession.getSelections().length).toBe 2 + [selection1, selection2] = editSession.getSelections() + expect(selection1.getBufferRange()).toEqual [[0,0], [0,5]] + expect(selection1.isReversed()).toBeTruthy() + expect(selection2.getBufferRange()).toEqual [[1,2], [1,7]] + expect(selection2.isReversed()).toBeTruthy() + + editSession.selectToFirstCharacterOfLine() + [selection1, selection2] = editSession.getSelections() + expect(selection1.getBufferRange()).toEqual [[0,0], [0,5]] + expect(selection1.isReversed()).toBeTruthy() + expect(selection2.getBufferRange()).toEqual [[1,0], [1,7]] + expect(selection2.isReversed()).toBeTruthy() + describe ".setSelectedBufferRanges(ranges)", -> it "clears existing selections and creates selections for each of the given ranges", -> editSession.setSelectedBufferRanges([[[2, 2], [3, 3]], [[4, 4], [5, 5]]]) diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index c38ba063d..efd93a654 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -1146,6 +1146,10 @@ class EditSession selectToBeginningOfLine: -> @expandSelectionsBackward (selection) => selection.selectToBeginningOfLine() + # Moves every cursor to the first non-whitespace character of the line. + selectToFirstCharacterOfLine: -> + @expandSelectionsBackward (selection) => selection.selectToFirstCharacterOfLine() + # Selects all the text from the current cursor position to the end of the line. selectToEndOfLine: -> @expandSelectionsForward (selection) => selection.selectToEndOfLine() diff --git a/src/app/selection.coffee b/src/app/selection.coffee index 5c987791e..cb3ec1b27 100644 --- a/src/app/selection.coffee +++ b/src/app/selection.coffee @@ -198,6 +198,10 @@ class Selection selectToBeginningOfLine: -> @modifySelection => @cursor.moveToBeginningOfLine() + # Selects all the text from the current cursor position to the beginning of the line. + selectToFirstCharacterOfLine: -> + @modifySelection => @cursor.moveToFirstCharacterOfLine() + # Selects all the text from the current cursor position to the end of the line. selectToEndOfLine: -> @modifySelection => @cursor.moveToEndOfLine()