From f24a045e11707af85797a27d55eee14ebc6b5836 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 27 Feb 2012 13:07:59 -0700 Subject: [PATCH] Cursor can move to last row when lines are wrapped --- spec/atom/editor-spec.coffee | 7 +++++++ src/atom/cursor.coffee | 6 +----- src/atom/editor.coffee | 6 ++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index 1c3b235d3..ca3fd36c7 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -98,6 +98,13 @@ describe "Editor", -> $(window).trigger 'resize' expect(editor.setMaxLineLength).not.toHaveBeenCalled() + it "allows the cursor to move down to the last line", -> + _.times editor.lastScreenRow(), -> editor.moveCursorDown() + expect(editor.getCursorScreenPosition()).toEqual [editor.lastScreenRow(), 0] + editor.moveCursorDown() + expect(editor.getCursorScreenPosition()).toEqual [editor.lastScreenRow(), 2] + + describe "cursor movement", -> describe ".setCursorScreenPosition({row, column})", -> beforeEach -> diff --git a/src/atom/cursor.coffee b/src/atom/cursor.coffee index 87dfab2cf..f52460f41 100644 --- a/src/atom/cursor.coffee +++ b/src/atom/cursor.coffee @@ -60,11 +60,7 @@ class Cursor extends View moveDown: -> { row, column } = @getScreenPosition() column = @goalColumn if @goalColumn? - if row < @editor.buffer.numLines() - 1 - @setScreenPosition({row: row + 1, column: column}) - else - @moveToLineEnd() - + @setScreenPosition({row: row + 1, column: column}) @goalColumn = column moveToLineEnd: -> diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index d690a4565..b822d41af 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -141,6 +141,12 @@ class Editor extends View linesForScreenRows: (start, end) -> @lineWrapper.linesForScreenRows(start, end) + screenLineCount: -> + @lineWrapper.lineCount() + + lastScreenRow: -> + @screenLineCount() - 1 + setBuffer: (@buffer) -> @highlighter = new Highlighter(@buffer) @lineFolder = new LineFolder(@highlighter)