Restore markers before triggering buffer events

This allows folds to be restored on undo/redo
This commit is contained in:
Nathan Sobo 2013-04-30 18:21:37 -06:00
parent af903f6690
commit df08c14aef
2 changed files with 13 additions and 1 deletions

View File

@ -265,9 +265,10 @@ describe "DisplayBuffer", ->
changeHandler.reset()
describe "when the old range surrounds a fold", ->
it "removes the fold and replaces the selection with the new text", ->
beforeEach ->
buffer.change([[1, 0], [5, 1]], 'party!')
it "removes the fold and replaces the selection with the new text", ->
expect(displayBuffer.lineForRow(0).text).toBe "0"
expect(displayBuffer.lineForRow(1).text).toBe "party!"
expect(displayBuffer.lineForRow(2).fold).toBe fold2
@ -275,6 +276,13 @@ describe "DisplayBuffer", ->
expect(changeHandler).toHaveBeenCalledWith(start: 1, end: 3, screenDelta: -2, bufferDelta: -4)
describe "when the changes is subsequently undone", ->
it "restores destroyed folds", ->
buffer.undo()
expect(displayBuffer.lineForRow(2).text).toBe '2'
expect(displayBuffer.lineForRow(2).fold).toBe fold1
expect(displayBuffer.lineForRow(3).text).toBe '5'
describe "when the old range surrounds two nested folds", ->
it "removes both folds and replaces the selection with the new text", ->
displayBuffer.createFold(2, 9)

View File

@ -19,6 +19,7 @@ class BufferChangeOperation
@options ?= {}
do: ->
@buffer.pauseEvents()
@pauseMarkerObservation()
@oldText = @buffer.getTextInRange(@oldRange)
@newRange = @calculateNewRange(@oldRange, @newText)
@ -29,10 +30,12 @@ class BufferChangeOperation
oldText: @oldText
newText: @newText
@restoreMarkers(@markersToRestoreOnRedo) if @markersToRestoreOnRedo
@buffer.resumeEvents()
@resumeMarkerObservation()
newRange
undo: ->
@buffer.pauseEvents()
@pauseMarkerObservation()
@markersToRestoreOnRedo = @invalidateMarkers(@newRange)
@changeBuffer
@ -41,6 +44,7 @@ class BufferChangeOperation
oldText: @newText
newText: @oldText
@restoreMarkers(@markersToRestoreOnUndo)
@buffer.resumeEvents()
@resumeMarkerObservation()
splitLines: (text) ->