mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Throw exception when aborting/committing without a transaction
This commit is contained in:
@@ -157,6 +157,12 @@ describe "UndoManager", ->
|
||||
undoManager.redo()
|
||||
expect(buffer.getText()).toBe '12'
|
||||
|
||||
describe "commit", ->
|
||||
it "throws an exception if there is no current transaction", ->
|
||||
expect(->
|
||||
buffer.commit()
|
||||
).toThrow()
|
||||
|
||||
describe "abort", ->
|
||||
it "does not affect the undo stack when the current transaction is empty", ->
|
||||
buffer.setText('')
|
||||
@@ -167,6 +173,11 @@ describe "UndoManager", ->
|
||||
buffer.undo()
|
||||
expect(buffer.getText()).toBe ''
|
||||
|
||||
it "throws an exception if there is no current transaction", ->
|
||||
expect(->
|
||||
buffer.abort()
|
||||
).toThrow()
|
||||
|
||||
describe "when a `do` operation throws an exception", ->
|
||||
it "clears the stack", ->
|
||||
spyOn(console, 'error')
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user