mirror of
https://github.com/atom/atom.git
synced 2026-02-08 05:35:04 -05:00
Add UndoManager.prototype.transact
The `transact` method takes a function and batches all operations within that function as a single transaction to be undone and redone. The edit session now uses generic operations to restore selection state around transactions. The `undo` and `do` methods on operations are now optional. In addition, the undo manager now supports an optional `redo` method on an operation for code that should *only* be run on redo, and not when the operation is initially pushed. This is used by edit session to restore selection state after redo.
This commit is contained in:
@@ -132,10 +132,7 @@ class Buffer
|
||||
change: (oldRange, newText) ->
|
||||
oldRange = Range.fromObject(oldRange)
|
||||
operation = new BufferChangeOperation({buffer: this, oldRange, newText})
|
||||
if @undoManager
|
||||
@undoManager.pushOperation(operation)
|
||||
else
|
||||
operation.do()
|
||||
@pushOperation(operation)
|
||||
|
||||
prefixAndSuffixForRange: (range) ->
|
||||
prefix: @lines[range.start.row][0...range.start.column]
|
||||
@@ -145,11 +142,14 @@ class Buffer
|
||||
@lines[startRow..endRow] = newLines
|
||||
@modified = true
|
||||
|
||||
startUndoBatch: (selectedBufferRanges) ->
|
||||
@undoManager.startUndoBatch(selectedBufferRanges)
|
||||
pushOperation: (operation) ->
|
||||
if @undoManager
|
||||
@undoManager.pushOperation(operation)
|
||||
else
|
||||
operation.do()
|
||||
|
||||
endUndoBatch: (selectedBufferRanges) ->
|
||||
@undoManager.endUndoBatch(selectedBufferRanges)
|
||||
transact: (fn) ->
|
||||
@undoManager.transact(fn)
|
||||
|
||||
undo: ->
|
||||
@undoManager.undo()
|
||||
|
||||
Reference in New Issue
Block a user