mirror of
https://github.com/atom/atom.git
synced 2026-02-14 08:35:11 -05:00
Add UndoManager.abort and .commit
When `UndoManager.transact` is called with no function, you later need to `abort` or `commit` the transaction manually. This allows transactions to last longer than the dynamic scope of the single function passed to `transact`.
This commit is contained in:
@@ -29,19 +29,22 @@ class UndoManager
|
||||
@clear()
|
||||
|
||||
transact: (fn) ->
|
||||
safeFn = ->
|
||||
shouldCommit = not @currentTransaction?
|
||||
@currentTransaction ?= []
|
||||
if fn
|
||||
try
|
||||
fn()
|
||||
catch e
|
||||
console.error e.stack
|
||||
finally
|
||||
@commit() if shouldCommit
|
||||
|
||||
if @currentTransaction
|
||||
safeFn()
|
||||
else
|
||||
@currentTransaction = []
|
||||
safeFn()
|
||||
@undoHistory.push(@currentTransaction) if @currentTransaction?.length
|
||||
@currentTransaction = null
|
||||
commit: ->
|
||||
@undoHistory.push(@currentTransaction) if @currentTransaction?.length
|
||||
@currentTransaction = null
|
||||
|
||||
abort: ->
|
||||
@commit()
|
||||
@undo()
|
||||
@redoHistory.pop()
|
||||
|
||||
undo: (editSession) ->
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user