From 84ea1017f473330bd9cd8dafa6f4d77d02dcd33f Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 31 Oct 2012 14:15:13 -0700 Subject: [PATCH] Anchor.ignoreEqual works properly The anchor ignores buffer changes when ignoreEqual is true and the oldRange.start == anchor.position --- spec/app/buffer-spec.coffee | 28 ++++++++++++++++++++++++++++ src/app/anchor.coffee | 6 ++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/spec/app/buffer-spec.coffee b/spec/app/buffer-spec.coffee index ad48c9aea..4ca5f1929 100644 --- a/spec/app/buffer-spec.coffee +++ b/spec/app/buffer-spec.coffee @@ -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", -> diff --git a/src/app/anchor.coffee b/src/app/anchor.coffee index 2755974c0..794061da9 100644 --- a/src/app/anchor.coffee +++ b/src/app/anchor.coffee @@ -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