mirror of
https://github.com/atom/atom.git
synced 2026-01-25 14:59:03 -05:00
Autoscroll the last cursor when it inserts text
Normally, we don't autoscroll to a cursor when the buffer changes. But this is a change caused by the cursor itself, so it makes sense to keep it in view.
This commit is contained in:
@@ -1155,6 +1155,15 @@ describe "Editor", ->
|
||||
editor.setCursorBufferPosition([4, 10])
|
||||
expect(editor.scrollToPixelPosition).toHaveBeenCalled()
|
||||
|
||||
it "does not autoscroll the cursor based on a buffer change, unless the buffer change was initiated by the cursor", ->
|
||||
lastVisibleRow = editor.getLastVisibleScreenRow()
|
||||
editor.addCursorAtBufferPosition([lastVisibleRow, 0])
|
||||
spyOn(editor, 'scrollToPixelPosition')
|
||||
buffer.insert([lastVisibleRow, 0], "\n\n")
|
||||
expect(editor.scrollToPixelPosition).not.toHaveBeenCalled()
|
||||
editor.insertText('\n\n')
|
||||
expect(editor.scrollToPixelPosition.callCount).toBe 1
|
||||
|
||||
describe "when the last cursor exceeds the upper or lower scroll margins", ->
|
||||
describe "when the editor is taller than twice the vertical scroll margin", ->
|
||||
it "sets the scrollTop so the cursor remains within the scroll margin", ->
|
||||
|
||||
@@ -154,6 +154,7 @@ class Selection
|
||||
wasReversed = @isReversed()
|
||||
text = @normalizeIndent(text, options) if options.normalizeIndent
|
||||
@clear()
|
||||
@cursor.needsAutoscroll = @cursor.isLastCursor()
|
||||
newBufferRange = @editSession.buffer.change(oldBufferRange, text)
|
||||
if options.select
|
||||
@setBufferRange(newBufferRange, reverse: wasReversed)
|
||||
|
||||
Reference in New Issue
Block a user