Add EditSession.transact and friends

`EditSession.transact` adds more semantics on top of `UndoManager`'s
version pertaining to restoring selections on undo/redo of the
transaction.
This commit is contained in:
Kevin Sawicki & Nathan Sobo
2013-01-04 12:42:09 -07:00
parent e65c2df093
commit ec13c38c7d
4 changed files with 51 additions and 23 deletions

View File

@@ -235,6 +235,27 @@ class EditSession
redo: ->
@buffer.redo(this)
transact: (fn) ->
isNewTransaction = @buffer.transact()
console.log isNewTransaction
oldSelectedRanges = @getSelectedBufferRanges()
@pushOperation
undo: (editSession) ->
editSession?.setSelectedBufferRanges(oldSelectedRanges)
if fn
fn()
@commit() if isNewTransaction
commit: ->
newSelectedRanges = @getSelectedBufferRanges()
@pushOperation
redo: (editSession) ->
editSession?.setSelectedBufferRanges(newSelectedRanges)
@buffer.commit()
abort: ->
@buffer.abort()
foldAll: ->
@displayBuffer.foldAll()
@@ -303,19 +324,6 @@ class EditSession
mutateSelectedText: (fn) ->
@transact => fn(selection) for selection in @getSelections()
transact: (fn) ->
@buffer.transact =>
oldSelectedRanges = @getSelectedBufferRanges()
@pushOperation
undo: (editSession) ->
editSession?.setSelectedBufferRanges(oldSelectedRanges)
fn()
newSelectedRanges = @getSelectedBufferRanges()
@pushOperation
redo: (editSession) ->
editSession?.setSelectedBufferRanges(newSelectedRanges)
pushOperation: (operation) ->
@buffer.pushOperation(operation, this)