mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Suppress merging selections during undo/redo
Now, during undo/redo overlapping selections will be temporarily created as markers are created via snapshots. Old selections will immediately be destroyed though, since undo/redo now completely replace all historied markers w/ those in the snapshot, so there is no need to merge selections.
This commit is contained in:
@@ -3417,6 +3417,63 @@ describe "TextEditor", ->
|
||||
expect(buffer.lineForRow(0)).not.toContain "foo"
|
||||
expect(buffer.lineForRow(0)).toContain "fovar"
|
||||
|
||||
it "restores cursors and selections to their states before and after undone and redone changes", ->
|
||||
editor.setSelectedBufferRanges([
|
||||
[[0, 0], [0, 0]],
|
||||
[[1, 0], [1, 3]],
|
||||
])
|
||||
editor.insertText("abc")
|
||||
|
||||
expect(editor.getSelectedBufferRanges()).toEqual [
|
||||
[[0, 3], [0, 3]],
|
||||
[[1, 3], [1, 3]]
|
||||
]
|
||||
|
||||
editor.setCursorBufferPosition([0, 0])
|
||||
editor.setSelectedBufferRanges([
|
||||
[[2, 0], [2, 0]],
|
||||
[[3, 0], [3, 0]],
|
||||
[[4, 0], [4, 3]],
|
||||
])
|
||||
editor.insertText("def")
|
||||
|
||||
expect(editor.getSelectedBufferRanges()).toEqual [
|
||||
[[2, 3], [2, 3]],
|
||||
[[3, 3], [3, 3]]
|
||||
[[4, 3], [4, 3]]
|
||||
]
|
||||
|
||||
editor.setCursorBufferPosition([0, 0])
|
||||
editor.undo()
|
||||
|
||||
expect(editor.getSelectedBufferRanges()).toEqual [
|
||||
[[2, 0], [2, 0]],
|
||||
[[3, 0], [3, 0]],
|
||||
[[4, 0], [4, 3]],
|
||||
]
|
||||
|
||||
editor.undo()
|
||||
|
||||
expect(editor.getSelectedBufferRanges()).toEqual [
|
||||
[[0, 0], [0, 0]],
|
||||
[[1, 0], [1, 3]]
|
||||
]
|
||||
|
||||
editor.redo()
|
||||
|
||||
expect(editor.getSelectedBufferRanges()).toEqual [
|
||||
[[0, 3], [0, 3]],
|
||||
[[1, 3], [1, 3]]
|
||||
]
|
||||
|
||||
editor.redo()
|
||||
|
||||
expect(editor.getSelectedBufferRanges()).toEqual [
|
||||
[[2, 3], [2, 3]],
|
||||
[[3, 3], [3, 3]]
|
||||
[[4, 3], [4, 3]]
|
||||
]
|
||||
|
||||
it "restores the selected ranges after undo and redo", ->
|
||||
editor.setSelectedBufferRanges([[[1, 6], [1, 10]], [[1, 22], [1, 27]]])
|
||||
editor.delete()
|
||||
|
||||
@@ -1119,12 +1119,12 @@ class TextEditor extends Model
|
||||
|
||||
# Essential: Undo the last change.
|
||||
undo: ->
|
||||
@buffer.undo()
|
||||
@avoidMergingSelections => @buffer.undo()
|
||||
@getLastSelection().autoscroll()
|
||||
|
||||
# Essential: Redo the last change.
|
||||
redo: ->
|
||||
@buffer.redo(this)
|
||||
@avoidMergingSelections => @buffer.redo()
|
||||
@getLastSelection().autoscroll()
|
||||
|
||||
# Extended: Batch multiple operations as a single undo/redo step.
|
||||
@@ -2217,6 +2217,9 @@ class TextEditor extends Model
|
||||
|
||||
previousSelection.intersectsScreenRowRange(screenRange.start.row, screenRange.end.row)
|
||||
|
||||
avoidMergingSelections: (args...) ->
|
||||
@mergeSelections args..., -> false
|
||||
|
||||
mergeSelections: (args...) ->
|
||||
mergePredicate = args.pop()
|
||||
fn = args.pop() if _.isFunction(_.last(args))
|
||||
|
||||
Reference in New Issue
Block a user