Add columnCount to moveRight

This commit is contained in:
Ben Ogle
2014-09-03 15:54:46 -07:00
parent 29f15d0f20
commit f82c59d865
3 changed files with 39 additions and 5 deletions

View File

@@ -343,7 +343,7 @@ describe "Editor", ->
editor.moveLeft()
expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: buffer.lineForRow(0).length)
it "moves the cursor by one row up columns to the left", ->
it "moves the cursor by one row up and n columns to the left", ->
editor.setCursorScreenPosition([1, 0])
editor.moveLeft(4)
expect(editor.getCursorScreenPosition()).toEqual [0, 26]
@@ -393,6 +393,21 @@ describe "Editor", ->
editor.moveRight()
expect(editor.getCursorScreenPosition()).toEqual [3, 4]
it "moves the cursor by n columns to the right", ->
editor.setCursorScreenPosition([3, 7])
editor.moveRight(4)
expect(editor.getCursorScreenPosition()).toEqual [3, 11]
it "moves the cursor by two rows down when the columnCount is longer than an entire line", ->
editor.setCursorScreenPosition([0, 28])
editor.moveRight(32)
expect(editor.getCursorScreenPosition()).toEqual [2, 0]
it "moves the cursor to the end of the buffer when columnCount is longer than the number of characters following the cursor position", ->
editor.setCursorScreenPosition([11, 5])
editor.moveRight(100)
expect(editor.getCursorScreenPosition()).toEqual [12, 2]
describe "when the cursor is on the last column of a line", ->
describe "when there is a subsequent line", ->
it "wraps to the beginning of the next line", ->
@@ -400,6 +415,11 @@ describe "Editor", ->
editor.moveRight()
expect(editor.getCursorScreenPosition()).toEqual [1, 0]
it "moves the cursor by one row down and n columns to the right", ->
editor.setCursorScreenPosition([0, buffer.lineForRow(0).length])
editor.moveRight(4)
expect(editor.getCursorScreenPosition()).toEqual [1, 3]
describe "when the cursor is on the last line", ->
it "remains in the same position", ->
lastLineIndex = buffer.getLines().length - 1

View File

@@ -290,13 +290,27 @@ class Cursor extends Model
# * `options` (optional) {Object} with the following keys:
# * `moveToEndOfSelection` if true, move to the right of the selection if a
# selection exists.
moveRight: ({moveToEndOfSelection}={}) ->
moveRight: (columnCount=1, {moveToEndOfSelection}={}) ->
range = @marker.getScreenRange()
if moveToEndOfSelection and not range.isEmpty()
@setScreenPosition(range.end)
else
{ row, column } = @getScreenPosition()
@setScreenPosition([row, column + 1], skipAtomicTokens: true, wrapBeyondNewlines: true, wrapAtSoftNewlines: true)
newColumn = column + columnCount
rowLength = @editor.lineTextForScreenRow(row).length
if newColumn <= rowLength
column = newColumn
else
columnDelta = newColumn - rowLength - 1
maxLines = @editor.getScreenLineCount()
while columnDelta >= 0 and row < maxLines - 1
row++
rowLength = @editor.lineTextForScreenRow(row).length
column = columnDelta
columnDelta -= rowLength
@setScreenPosition({row, column}, skipAtomicTokens: true, wrapBeyondNewlines: true, wrapAtSoftNewlines: true)
# Public: Moves the cursor to the top of the buffer.
moveToTop: ->

View File

@@ -1643,8 +1643,8 @@ class Editor extends Model
@moveLeft()
# Essential: Move every cursor right one column.
moveRight: ->
@moveCursors (cursor) -> cursor.moveRight(moveToEndOfSelection: true)
moveRight: (columnCount) ->
@moveCursors (cursor) -> cursor.moveRight(columnCount, moveToEndOfSelection: true)
moveCursorRight: ->
deprecate("Use Editor::moveRight() instead")
@moveRight()