mirror of
https://github.com/atom/atom.git
synced 2026-02-09 14:15:24 -05:00
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:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -428,7 +428,8 @@ class Editor extends View
|
||||
foldSelection: -> @getSelection().fold()
|
||||
|
||||
undo: ->
|
||||
@buffer.undo()
|
||||
if ranges = @buffer.undo()
|
||||
@setSelectedBufferRanges(ranges)
|
||||
|
||||
redo: ->
|
||||
@buffer.redo()
|
||||
|
||||
Reference in New Issue
Block a user