Add columnCount var to Editor::moveLeft and Cursor::moveLeft

This commit is contained in:
Ben Ogle 2014-09-02 17:29:30 -07:00
parent 851034c8d3
commit 99c07decf2
3 changed files with 20 additions and 3 deletions

View File

@ -333,12 +333,22 @@ describe "Editor", ->
editor.moveLeft()
expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: buffer.lineForRow(0).length)
it "moves the cursor by n columns to the left", ->
editor.setCursorScreenPosition([1, 0])
editor.moveLeft(4)
expect(editor.getCursorScreenPosition()).toEqual [0, 26]
describe "when the cursor is on the first line", ->
it "remains in the same position (0,0)", ->
editor.setCursorScreenPosition(row: 0, column: 0)
editor.moveLeft()
expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0)
it "moves the cursor by n columns to the left", ->
editor.setCursorScreenPosition([0, 0])
editor.moveLeft(4)
expect(editor.getCursorScreenPosition()).toEqual [0, 0]
describe "when softTabs is enabled and the cursor is preceded by leading whitespace", ->
it "skips tabLength worth of whitespace at a time", ->
editor.setCursorBufferPosition([5, 6])

View File

@ -270,7 +270,14 @@ class Cursor extends Model
@setScreenPosition(range.start)
else
{row, column} = @getScreenPosition()
[row, column] = if column > 0 then [row, column - 1] else [row - 1, Infinity]
newColumn = column - columnCount
if newColumn >= 0
column = newColumn
else if row > 0
row--
column = @editor.lineTextForScreenRow(row).length + newColumn + 1
@setScreenPosition({row, column})
# Public: Moves the cursor right one screen column.

View File

@ -1636,8 +1636,8 @@ class Editor extends Model
@moveDown(lineCount)
# Essential: Move every cursor left one column.
moveLeft: ->
@moveCursors (cursor) -> cursor.moveLeft(moveToEndOfSelection: true)
moveLeft: (columnCount) ->
@moveCursors (cursor) -> cursor.moveLeft(columnCount, moveToEndOfSelection: true)
moveCursorLeft: ->
deprecate("Use Editor::moveLeft() instead")
@moveLeft()