From 99c07decf2d9444df659cc2f2f5dc7289ed3257c Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 2 Sep 2014 17:29:30 -0700 Subject: [PATCH] Add `columnCount` var to Editor::moveLeft and Cursor::moveLeft --- spec/editor-spec.coffee | 10 ++++++++++ src/cursor.coffee | 9 ++++++++- src/editor.coffee | 4 ++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index a97a5d2dd..053a81573 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -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]) diff --git a/src/cursor.coffee b/src/cursor.coffee index 23343fc3d..b2c00ce71 100644 --- a/src/cursor.coffee +++ b/src/cursor.coffee @@ -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. diff --git a/src/editor.coffee b/src/editor.coffee index 337b5da9d..0b3227507 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -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()