From df08c14aef52d6f944a50483f6a34f001aa4897e Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 30 Apr 2013 18:21:37 -0600 Subject: [PATCH] Restore markers before triggering buffer events This allows folds to be restored on undo/redo --- spec/app/display-buffer-spec.coffee | 10 +++++++++- src/app/buffer-change-operation.coffee | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/app/display-buffer-spec.coffee b/spec/app/display-buffer-spec.coffee index 754a4e176..9eab65aba 100644 --- a/spec/app/display-buffer-spec.coffee +++ b/spec/app/display-buffer-spec.coffee @@ -265,9 +265,10 @@ describe "DisplayBuffer", -> changeHandler.reset() describe "when the old range surrounds a fold", -> - it "removes the fold and replaces the selection with the new text", -> + beforeEach -> buffer.change([[1, 0], [5, 1]], 'party!') + it "removes the fold and replaces the selection with the new text", -> expect(displayBuffer.lineForRow(0).text).toBe "0" expect(displayBuffer.lineForRow(1).text).toBe "party!" expect(displayBuffer.lineForRow(2).fold).toBe fold2 @@ -275,6 +276,13 @@ describe "DisplayBuffer", -> expect(changeHandler).toHaveBeenCalledWith(start: 1, end: 3, screenDelta: -2, bufferDelta: -4) + describe "when the changes is subsequently undone", -> + it "restores destroyed folds", -> + buffer.undo() + expect(displayBuffer.lineForRow(2).text).toBe '2' + expect(displayBuffer.lineForRow(2).fold).toBe fold1 + expect(displayBuffer.lineForRow(3).text).toBe '5' + describe "when the old range surrounds two nested folds", -> it "removes both folds and replaces the selection with the new text", -> displayBuffer.createFold(2, 9) diff --git a/src/app/buffer-change-operation.coffee b/src/app/buffer-change-operation.coffee index c0910a7ce..16f4614f8 100644 --- a/src/app/buffer-change-operation.coffee +++ b/src/app/buffer-change-operation.coffee @@ -19,6 +19,7 @@ class BufferChangeOperation @options ?= {} do: -> + @buffer.pauseEvents() @pauseMarkerObservation() @oldText = @buffer.getTextInRange(@oldRange) @newRange = @calculateNewRange(@oldRange, @newText) @@ -29,10 +30,12 @@ class BufferChangeOperation oldText: @oldText newText: @newText @restoreMarkers(@markersToRestoreOnRedo) if @markersToRestoreOnRedo + @buffer.resumeEvents() @resumeMarkerObservation() newRange undo: -> + @buffer.pauseEvents() @pauseMarkerObservation() @markersToRestoreOnRedo = @invalidateMarkers(@newRange) @changeBuffer @@ -41,6 +44,7 @@ class BufferChangeOperation oldText: @newText newText: @oldText @restoreMarkers(@markersToRestoreOnUndo) + @buffer.resumeEvents() @resumeMarkerObservation() splitLines: (text) ->