From dba768747025de6b33a627b570691f0edd8cc457 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 6 Nov 2013 08:25:18 -0800 Subject: [PATCH 1/4] Autoscroll even when text does not change --- src/cursor.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cursor.coffee b/src/cursor.coffee index 128f0bb17..13e28b8f0 100644 --- a/src/cursor.coffee +++ b/src/cursor.coffee @@ -27,7 +27,7 @@ class Cursor {textChanged} = e return if oldHeadScreenPosition.isEqual(newHeadScreenPosition) - @needsAutoscroll ?= @isLastCursor() and !textChanged + @needsAutoscroll ?= @isLastCursor() movedEvent = oldBufferPosition: oldHeadBufferPosition From 291f4fbb90aaffa1a03295abb09beaaf11760ec2 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 6 Nov 2013 09:03:35 -0800 Subject: [PATCH 2/4] Mark last cursor for autoscroll on undo/redo --- spec/editor-spec.coffee | 10 ++++++++++ src/cursor.coffee | 2 +- src/edit-session.coffee | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 35e2f3dd8..2b841a02e 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -958,6 +958,16 @@ describe "Editor", -> editor.insertText('\n\n') expect(editor.scrollToPixelPosition.callCount).toBe 1 + it "autoscrolls on undo/redo", -> + editor.getCursor().clearAutoscroll() + spyOn(editor, 'scrollToPixelPosition').andCallThrough() + editor.insertText('\n\n') + expect(editor.scrollToPixelPosition.callCount).toBe 1 + editor.undo() + expect(editor.scrollToPixelPosition.callCount).toBe 2 + editor.redo() + expect(editor.scrollToPixelPosition.callCount).toBe 3 + 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", -> diff --git a/src/cursor.coffee b/src/cursor.coffee index 13e28b8f0..128f0bb17 100644 --- a/src/cursor.coffee +++ b/src/cursor.coffee @@ -27,7 +27,7 @@ class Cursor {textChanged} = e return if oldHeadScreenPosition.isEqual(newHeadScreenPosition) - @needsAutoscroll ?= @isLastCursor() + @needsAutoscroll ?= @isLastCursor() and !textChanged movedEvent = oldBufferPosition: oldHeadBufferPosition diff --git a/src/edit-session.coffee b/src/edit-session.coffee index 2cc8397e2..290fcc23a 100644 --- a/src/edit-session.coffee +++ b/src/edit-session.coffee @@ -574,10 +574,14 @@ class EditSession # Public: Undoes the last change. undo: -> + cursor = @getCursor() + cursor.needsAutoscroll = cursor.isLastCursor() @buffer.undo(this) # Pulic: Redoes the last change. redo: -> + cursor = @getCursor() + cursor.needsAutoscroll = cursor.isLastCursor() @buffer.redo(this) # Public: Folds all the rows. From 6b63f5db9e8c3dde294bf84d3bbdbf9cc7780d5c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 6 Nov 2013 09:08:14 -0800 Subject: [PATCH 3/4] Always mark cursor needing autoscroll --- src/edit-session.coffee | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/edit-session.coffee b/src/edit-session.coffee index 290fcc23a..5625da8d3 100644 --- a/src/edit-session.coffee +++ b/src/edit-session.coffee @@ -574,14 +574,12 @@ class EditSession # Public: Undoes the last change. undo: -> - cursor = @getCursor() - cursor.needsAutoscroll = cursor.isLastCursor() + @getCursor().needsAutoscroll = true @buffer.undo(this) # Pulic: Redoes the last change. redo: -> - cursor = @getCursor() - cursor.needsAutoscroll = cursor.isLastCursor() + @getCursor().needsAutoscroll = true @buffer.redo(this) # Public: Folds all the rows. From b4f8387053b2c24482e4e554495fc26be67805ed Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 6 Nov 2013 09:11:09 -0800 Subject: [PATCH 4/4] Remove unneded clearAutoscroll call --- spec/editor-spec.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 2b841a02e..ce9c64572 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -959,8 +959,7 @@ describe "Editor", -> expect(editor.scrollToPixelPosition.callCount).toBe 1 it "autoscrolls on undo/redo", -> - editor.getCursor().clearAutoscroll() - spyOn(editor, 'scrollToPixelPosition').andCallThrough() + spyOn(editor, 'scrollToPixelPosition') editor.insertText('\n\n') expect(editor.scrollToPixelPosition.callCount).toBe 1 editor.undo()