Restore selections after undo

This only restores changes made via the CompositeSelection… this makes sense because this is the only way to make changes interactively. Any other changes are made via the api or a command line and should not modify selections when they are undone. Still need to test restoration after redo.
This commit is contained in:
Nathan Sobo
2012-04-04 18:04:17 -06:00
parent 5def158584
commit cbeb351de4
5 changed files with 40 additions and 16 deletions

View File

@@ -127,11 +127,11 @@ class Buffer
@lines[oldRange.start.row..oldRange.end.row] = newTextLines
@trigger 'change', { oldRange, newRange, oldText, newText }
startUndoBatch: ->
@undoManager.startUndoBatch()
startUndoBatch: (selectedBufferRanges) ->
@undoManager.startUndoBatch(selectedBufferRanges)
endUndoBatch: ->
@undoManager.endUndoBatch()
endUndoBatch: (selectedBufferRanges) ->
@undoManager.endUndoBatch(selectedBufferRanges)
undo: ->
@undoManager.undo()

View File

@@ -16,6 +16,9 @@ class CompositeSeleciton
getSelections: ->
new Array(@selections...)
getSelectedBufferRanges: ->
selection.getBufferRange() for selection in @getSelections()
getLastSelection: ->
_.last(@selections)
@@ -57,10 +60,12 @@ class CompositeSeleciton
@getLastSelection().setBufferRange(bufferRange, options)
setBufferRanges: (bufferRanges) ->
@clearSelections()
@setBufferRange(bufferRanges[0])
for bufferRange in bufferRanges[1..]
@addSelectionForBufferRange(bufferRange)
selections = @getSelections()
for bufferRange, i in bufferRanges
if selections[i]
selections[i].setBufferRange(bufferRange)
else
@addSelectionForBufferRange(bufferRange)
@mergeIntersectingSelections()
getBufferRange: (bufferRange) ->
@@ -79,12 +84,9 @@ class CompositeSeleciton
mutateSelectedText: (fn) ->
selections = @getSelections()
if selections.length > 1
@editor.buffer.startUndoBatch()
fn(selection) for selection in selections
@editor.buffer.endUndoBatch()
else
fn(selections[0])
@editor.buffer.startUndoBatch(@getSelectedBufferRanges())
fn(selection) for selection in selections
@editor.buffer.endUndoBatch()
insertText: (text) ->
@mutateSelectedText (selection) -> selection.insertText(text)

View File

@@ -428,7 +428,8 @@ class Editor extends View
foldSelection: -> @getSelection().fold()
undo: ->
@buffer.undo()
if ranges = @buffer.undo()
@setSelectedBufferRanges(ranges)
redo: ->
@buffer.redo()