Add columnCounts to selection methods

This commit is contained in:
Ben Ogle
2014-09-03 16:20:25 -07:00
parent 7a3893c7bb
commit 48b693c1c1
3 changed files with 43 additions and 10 deletions

View File

@@ -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]])

View File

@@ -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.

View File

@@ -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)