From 48b693c1c17ad5a52b515bbf2941ea8251ef87d2 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 3 Sep 2014 16:20:25 -0700 Subject: [PATCH] Add columnCounts to selection methods --- spec/editor-spec.coffee | 21 +++++++++++++++++++++ src/editor.coffee | 16 ++++++++++------ src/selection.coffee | 16 ++++++++++++---- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index c2ca4c01a..e8c092ded 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -969,6 +969,27 @@ describe "Editor", -> expect(selection1.getScreenRange()).toEqual([[0, 9], [1, 21]]) expect(selection1.isReversed()).toBeFalsy() + describe "when counts are passed into the selection functions", -> + it "expands each selection to its cursor's new location", -> + editor.setSelectedBufferRanges([[[0,9], [0,13]], [[3,16], [3,21]]]) + [selection1, selection2] = editor.getSelections() + + editor.selectRight(2) + expect(selection1.getBufferRange()).toEqual [[0,9], [0,15]] + expect(selection2.getBufferRange()).toEqual [[3,16], [3,23]] + + editor.selectLeft(3) + expect(selection1.getBufferRange()).toEqual [[0,9], [0,12]] + expect(selection2.getBufferRange()).toEqual [[3,16], [3,20]] + + editor.selectDown(3) + expect(selection1.getBufferRange()).toEqual [[0,9], [3,12]] + expect(selection2.getBufferRange()).toEqual [[3,16], [6,20]] + + editor.selectUp(2) + expect(selection1.getBufferRange()).toEqual [[0,9], [1,12]] + expect(selection2.getBufferRange()).toEqual [[3,16], [4,20]] + describe ".selectToBufferPosition(bufferPosition)", -> it "expands the last selection to the given position", -> editor.setSelectedBufferRange([[3, 0], [4, 5]]) diff --git a/src/editor.coffee b/src/editor.coffee index 9d88d976e..3ade2ecb9 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -1982,7 +1982,7 @@ class Editor extends Model # Essential: Move the cursor of each selection one character upward while # preserving the selection's tail position. # - # * `rowCount` {Number} of rows to select up + # * `rowCount` (optional) {Number} number of rows to select (default: 1) # # This method may merge selections that end up intesecting. selectUp: (rowCount) -> @@ -1991,7 +1991,7 @@ class Editor extends Model # Essential: Move the cursor of each selection one character downward while # preserving the selection's tail position. # - # * `rowCount` {Number} of rows to select down + # * `rowCount` (optional) {Number} number of rows to select (default: 1) # # This method may merge selections that end up intesecting. selectDown: (rowCount) -> @@ -2000,16 +2000,20 @@ class Editor extends Model # Essential: Move the cursor of each selection one character leftward while # preserving the selection's tail position. # + # * `columnCount` (optional) {Number} number of columns to select (default: 1) + # # This method may merge selections that end up intesecting. - selectLeft: -> - @expandSelectionsBackward (selection) -> selection.selectLeft() + selectLeft: (columnCount) -> + @expandSelectionsBackward (selection) -> selection.selectLeft(columnCount) # Essential: Move the cursor of each selection one character rightward while # preserving the selection's tail position. # + # * `columnCount` (optional) {Number} number of columns to select (default: 1) + # # This method may merge selections that end up intesecting. - selectRight: -> - @expandSelectionsForward (selection) -> selection.selectRight() + selectRight: (columnCount) -> + @expandSelectionsForward (selection) -> selection.selectRight(columnCount) # Essential: Select from the top of the buffer to the end of the last selection # in the buffer. diff --git a/src/selection.coffee b/src/selection.coffee index a0db277c1..38198fef4 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -198,18 +198,26 @@ class Selection extends Model @modifySelection => @cursor.setBufferPosition(position) # Public: Selects the text one position right of the cursor. - selectRight: -> - @modifySelection => @cursor.moveRight() + # + # * `columnCount` (optional) {Number} number of columns to select (default: 1) + selectRight: (columnCount) -> + @modifySelection => @cursor.moveRight(columnCount) # Public: Selects the text one position left of the cursor. - selectLeft: -> - @modifySelection => @cursor.moveLeft() + # + # * `columnCount` (optional) {Number} number of columns to select (default: 1) + selectLeft: (columnCount) -> + @modifySelection => @cursor.moveLeft(columnCount) # Public: Selects all the text one position above the cursor. + # + # * `rowCount` (optional) {Number} number of rows to select (default: 1) selectUp: (rowCount) -> @modifySelection => @cursor.moveUp(rowCount) # Public: Selects all the text one position below the cursor. + # + # * `rowCount` (optional) {Number} number of rows to select (default: 1) selectDown: (rowCount) -> @modifySelection => @cursor.moveDown(rowCount)