Throw exception when aborting/committing without a transaction

This commit is contained in:
Kevin Sawicki & Nathan Sobo
2013-01-04 13:02:56 -07:00
parent da095cdfe9
commit 82d4550ff3
2 changed files with 17 additions and 4 deletions

View File

@@ -39,16 +39,18 @@ class UndoManager
isNewTransaction
commit: ->
@undoHistory.push(@currentTransaction) if @currentTransaction?.length
unless @currentTransaction?
throw new Error("Trying to commit when there is no current transaction")
empty = @currentTransaction.length is 0
@undoHistory.push(@currentTransaction) unless empty
@currentTransaction = null
not empty
abort: ->
@commit()
@undo()
@redoHistory.pop()
unless @currentTransaction?
throw new Error("Trying to abort when there is no current transaction")
if @commit()
@undo()
@redoHistory.pop()