From e93e4e933393ef7d6fdac49c7410d2675ebf7caa Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 1 Jul 2014 11:34:36 -0600 Subject: [PATCH] Autoscroll to the last cursor in model when inserting text Fixes #2787 --- spec/editor-spec.coffee | 11 +++++++++++ src/selection.coffee | 1 + 2 files changed, 12 insertions(+) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index d697b7491..bc227d76b 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -1483,6 +1483,17 @@ describe "Editor", -> expect(cursor1.getBufferPosition()).toEqual [1, 5] expect(cursor2.getBufferPosition()).toEqual [2, 7] + it "autoscrolls to the last cursor", -> + editor.manageScrollPosition = true + editor.setCursorScreenPosition([1, 2]) + editor.addCursorAtScreenPosition([10, 4]) + editor.setLineHeightInPixels(10) + editor.setHeight(50) + + expect(editor.getScrollTop()).toBe 0 + editor.insertText('a') + expect(editor.getScrollTop()).toBe 80 + describe "when there are multiple non-empty selections", -> describe "when the selections are on the same line", -> it "replaces each selection range with the inserted characters", -> diff --git a/src/selection.coffee b/src/selection.coffee index c27f63f92..2945801d4 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -315,6 +315,7 @@ 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)