mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Anchor.ignoreEqual works properly
The anchor ignores buffer changes when ignoreEqual is true and the oldRange.start == anchor.position
This commit is contained in:
@@ -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", ->
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user