From 260be2e09677f40f5fd3ccd3c44eae2b1209c7cb Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 3 Jul 2014 14:47:28 -0600 Subject: [PATCH] Autoscroll *after* inserting text, not before Fixes #2787 --- spec/editor-spec.coffee | 7 +++++++ src/selection.coffee | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index bc227d76b..290710df7 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -785,6 +785,13 @@ describe "Editor", -> editor.moveCursorLeft() expect(editor.getScrollLeft()).toBe 58 * 10 + it "scrolls down when inserting lines makes the document longer than the editor's height", -> + editor.setCursorScreenPosition([13, Infinity]) + editor.insertNewline() + expect(editor.getScrollBottom()).toBe 14 * 10 + editor.insertNewline() + expect(editor.getScrollBottom()).toBe 15 * 10 + describe "selection", -> selection = null diff --git a/src/selection.coffee b/src/selection.coffee index 2945801d4..5990bec9f 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -315,12 +315,14 @@ class Selection extends Model wasReversed = @isReversed() @clear() @cursor.needsAutoscroll = @cursor.isLastCursor() - @cursor.autoscroll() if @editor.manageScrollPosition and @cursor.isLastCursor() if options.indentBasis? and not options.autoIndent text = @normalizeIndents(text, options.indentBasis) newBufferRange = @editor.buffer.setTextInRange(oldBufferRange, text, pick(options, 'undo')) + + @cursor.autoscroll() if @editor.manageScrollPosition and @cursor.isLastCursor() + if options.select @setBufferRange(newBufferRange, reversed: wasReversed) else