From da095cdfe95a4d83b12d7791236a4dcee21b4c15 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki & Nathan Sobo Date: Fri, 4 Jan 2013 13:01:23 -0700 Subject: [PATCH] Leave the undo stack intact when aborting empty transactions --- spec/app/undo-manager-spec.coffee | 9 +++++++++ src/app/undo-manager.coffee | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/spec/app/undo-manager-spec.coffee b/spec/app/undo-manager-spec.coffee index 32f141667..df1c9c690 100644 --- a/spec/app/undo-manager-spec.coffee +++ b/spec/app/undo-manager-spec.coffee @@ -157,6 +157,15 @@ describe "UndoManager", -> undoManager.redo() expect(buffer.getText()).toBe '12' + describe "abort", -> + it "does not affect the undo stack when the current transaction is empty", -> + buffer.setText('') + buffer.append('1') + buffer.transact() + buffer.abort() + expect(buffer.getText()).toBe '1' + buffer.undo() + expect(buffer.getText()).toBe '' describe "when a `do` operation throws an exception", -> it "clears the stack", -> diff --git a/src/app/undo-manager.coffee b/src/app/undo-manager.coffee index e910bc819..aa025668b 100644 --- a/src/app/undo-manager.coffee +++ b/src/app/undo-manager.coffee @@ -40,12 +40,18 @@ class UndoManager commit: -> @undoHistory.push(@currentTransaction) if @currentTransaction?.length + empty = @currentTransaction.length is 0 + @undoHistory.push(@currentTransaction) unless empty @currentTransaction = null + not empty abort: -> @commit() @undo() @redoHistory.pop() + if @commit() + @undo() + @redoHistory.pop() undo: (editSession) -> try