From f60f1692fd7cb8d2733c24d662fe78213d3bc20e Mon Sep 17 00:00:00 2001 From: Matthew Dapena-Tretter Date: Thu, 5 Jul 2018 19:18:58 -0700 Subject: [PATCH] Reset goal column on all cursor changes Previously, pressing the home key (move-to-first-character-of-line) while on an empty line wouldn't clear the goal column. This is because it was only cleared on cursor *change* and that didn't result in a change. With this commit, it's *always* cleared. Operations that want to preserve the goal column can reset it afterwards. --- spec/text-editor-spec.js | 9 +++++++++ src/cursor.js | 3 +++ 2 files changed, 12 insertions(+) diff --git a/spec/text-editor-spec.js b/spec/text-editor-spec.js index a84a1f233f9..eba2c34f747 100644 --- a/spec/text-editor-spec.js +++ b/spec/text-editor-spec.js @@ -861,6 +861,15 @@ describe('TextEditor', () => { }) }) }) + + it("clears the goal column", () => { + editor.setText('first\n\nthird') + editor.setCursorScreenPosition([0, 3]) + editor.moveDown() + editor.moveToFirstCharacterOfLine() + editor.moveDown() + expect(editor.getCursorBufferPosition()).toEqual([2, 0]) + }) }) describe('.moveToBeginningOfWord()', () => { diff --git a/src/cursor.js b/src/cursor.js index f62672f2767..f75f947091f 100644 --- a/src/cursor.js +++ b/src/cursor.js @@ -326,7 +326,9 @@ class Cursor extends Model { // Public: Moves the cursor to the bottom of the buffer. moveToBottom () { + const column = this.goalColumn this.setBufferPosition(this.editor.getEofBufferPosition()) + this.goalColumn = column } // Public: Moves the cursor to the beginning of the line. @@ -711,6 +713,7 @@ class Cursor extends Model { changePosition (options, fn) { this.clearSelection({autoscroll: false}) fn() + this.goalColumn = null const autoscroll = (options && options.autoscroll != null) ? options.autoscroll : this.isLastCursor()