Preserve folds when restoring selections on undo/redo

This commit is contained in:
Nathan Sobo
2013-04-30 18:39:54 -06:00
parent df08c14aef
commit 693c4f8270
2 changed files with 25 additions and 2 deletions

View File

@@ -2038,6 +2038,29 @@ describe "EditSession", ->
editSession.redo()
expect(editSession.getSelectedBufferRanges()).toEqual [[[1, 6], [1, 6]], [[1, 18], [1, 18]]]
it "restores folds after undo and redo", ->
editSession.foldBufferRow(1)
editSession.setSelectedBufferRange([[1, 0], [10, Infinity]], preserveFolds: true)
expect(editSession.isFoldedAtBufferRow(1)).toBeTruthy()
editSession.insertText """
\ // testing
function foo() {
return 1 + 2;
}
"""
expect(editSession.isFoldedAtBufferRow(1)).toBeFalsy()
editSession.foldBufferRow(2)
editSession.undo()
expect(editSession.isFoldedAtBufferRow(1)).toBeTruthy()
expect(editSession.isFoldedAtBufferRow(9)).toBeTruthy()
expect(editSession.isFoldedAtBufferRow(10)).toBeFalsy()
editSession.redo()
expect(editSession.isFoldedAtBufferRow(1)).toBeFalsy()
expect(editSession.isFoldedAtBufferRow(2)).toBeTruthy()
it "restores selected ranges even when the change occurred in another edit session", ->
otherEditSession = project.buildEditSession(editSession.getPath())
otherEditSession.setSelectedBufferRange([[2, 2], [3, 3]])

View File

@@ -623,7 +623,7 @@ class EditSession
oldSelectedRanges = @getSelectedBufferRanges()
@pushOperation
undo: (editSession) ->
editSession?.setSelectedBufferRanges(oldSelectedRanges)
editSession?.setSelectedBufferRanges(oldSelectedRanges, preserveFolds: true)
if fn
result = fn()
@commit() if isNewTransaction
@@ -633,7 +633,7 @@ class EditSession
newSelectedRanges = @getSelectedBufferRanges()
@pushOperation
redo: (editSession) ->
editSession?.setSelectedBufferRanges(newSelectedRanges)
editSession?.setSelectedBufferRanges(newSelectedRanges, preserveFolds: true)
@buffer.commit()
abort: ->