Restore invalidated anchor points on undo/redo of a change

This commit is contained in:
Nathan Sobo
2013-01-30 12:48:29 -07:00
parent 30909a8e8f
commit ec3a1a80cd

View File

@@ -665,7 +665,7 @@ describe 'Buffer', ->
anchor2Id = buffer.addAnchorPoint([4, 23], ignoreSameLocationInserts: true)
anchor3Id = buffer.addAnchorPoint([4, 23], surviveSurroundingChanges: true)
describe "when the buffer changes", ->
describe "when the buffer changes due to a new operation", ->
describe "when the change precedes the anchor point", ->
it "moves the anchor", ->
buffer.insert([4, 5], '...')
@@ -716,6 +716,21 @@ describe 'Buffer', ->
buffer.undo()
expect(buffer.getAnchorPoint(anchor1Id)).toEqual [4, 23]
describe "when the buffer changes due to the undo or redo of a previous operation", ->
it "restores invalidated anchor points when undoing/redoing in the other direction", ->
buffer.change([[4, 21], [4, 24]], "foo")
expect(buffer.getAnchorPoint(anchor1Id)).toBeUndefined()
anchor4Id = buffer.addAnchorPoint([4, 23])
buffer.undo()
expect(buffer.getAnchorPoint(anchor1Id)).toEqual [4, 23]
expect(buffer.getAnchorPoint(anchor4Id)).toBeUndefined()
anchor5Id = buffer.addAnchorPoint([4, 23])
buffer.redo()
expect(buffer.getAnchorPoint(anchor4Id)).toEqual [4, 23]
expect(buffer.getAnchorPoint(anchor5Id)).toBeUndefined()
buffer.undo()
expect(buffer.getAnchorPoint(anchor5Id)).toEqual [4, 23]
describe "anchors", ->
[anchor, destroyHandler] = []