Anchor.ignoreEqual works properly

The anchor ignores buffer changes when ignoreEqual is true and the oldRange.start == anchor.position
This commit is contained in:
Corey Johnson
2012-10-31 14:15:13 -07:00
parent 7793a04172
commit 84ea1017f4
2 changed files with 30 additions and 4 deletions

View File

@@ -630,6 +630,34 @@ describe 'Buffer', ->
anchor = buffer.addAnchorAtPosition([4, 25])
anchor.on 'destroy', destroyHandler
describe "when anchor.ignoreEqual is true", ->
beforeEach ->
anchor.ignoreEqual = true
describe "when the change ends before the anchor position", ->
it "moves the anchor", ->
buffer.change([[4, 23], [4, 24]], "...")
expect(anchor.getBufferPosition()).toEqual [4, 27]
expect(destroyHandler).not.toHaveBeenCalled()
describe "when the change ends on the anchor position", ->
it "moves the anchor", ->
buffer.change([[4, 24], [4, 25]], "...")
expect(anchor.getBufferPosition()).toEqual [4, 27]
expect(destroyHandler).not.toHaveBeenCalled()
describe "when the change begins on the anchor position", ->
it "doesn't move the anchor", ->
buffer.change([[4, 25], [4, 26]], ".....")
expect(anchor.getBufferPosition()).toEqual [4, 25]
expect(destroyHandler).not.toHaveBeenCalled()
describe "when the change begins after the anchor position", ->
it "doesn't move the anchor", ->
buffer.change([[4, 26], [4, 27]], ".....")
expect(anchor.getBufferPosition()).toEqual [4, 25]
expect(destroyHandler).not.toHaveBeenCalled()
describe "when the buffer changes and the oldRange is equalTo than the newRange (text is replaced)", ->
describe "when the anchor is contained by the oldRange", ->
it "destroys the anchor", ->

View File

@@ -25,10 +25,8 @@ class Anchor
@destroy()
return
if @ignoreEqual
return if position.isLessThanOrEqual(oldRange.end)
else
return if position.isLessThan(oldRange.end)
return if @ignoreEqual and position.isEqual(oldRange.start)
return if position.isLessThan(oldRange.end)
newRow = newRange.end.row
newColumn = newRange.end.column