From 88cf574bc62d422214b8c4668aa507cd827004bb Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 3 Feb 2012 16:07:54 -0800 Subject: [PATCH] Positioning the cursor beyond the bottom of the buffer will clip it to the last column of the last row --- spec/atom/editor-spec.coffee | 2 +- src/atom/editor.coffee | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index d30ed226a..08a9f4886 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -632,7 +632,7 @@ describe "Editor", -> describe ".clipPosition(point)", -> it "selects the nearest valid position to the given point", -> - expect(editor.clipPosition(row: 1000, column: 0)).toEqual(row: buffer.numLines() - 1, column: 0) + expect(editor.clipPosition(row: 1000, column: 0)).toEqual(row: buffer.lastRow(), column: buffer.getLine(buffer.lastRow()).length) expect(editor.clipPosition(row: -5, column: 0)).toEqual(row: 0, column: 0) expect(editor.clipPosition(row: 1, column: 10000)).toEqual(row: 1, column: buffer.getLine(1).length) expect(editor.clipPosition(row: 1, column: -5)).toEqual(row: 1, column: 0) diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 65cff93bb..4c0e83d11 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -161,8 +161,13 @@ class Editor extends Template @lines.find("pre.line:eq(#{row})") clipPosition: ({row, column}) -> - row = Math.min(Math.max(0, row), @buffer.numLines() - 1) - column = Math.min(Math.max(0, column), @buffer.getLine(row).length) + if row > @buffer.lastRow() + row = @buffer.lastRow() + column = @buffer.getLine(row).length + else + row = Math.min(Math.max(0, row), @buffer.numLines() - 1) + column = Math.min(Math.max(0, column), @buffer.getLine(row).length) + new Point(row, column) pixelPositionFromPoint: ({row, column}) ->