mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Anchors are destroyed when encompassed by a buffer change
This commit is contained in:
@@ -1331,6 +1331,28 @@ describe "EditSession", ->
|
||||
editSession.foldAll()
|
||||
expect(editSession.getCursorBufferPosition()).toEqual([5,5])
|
||||
|
||||
describe "anchors", ->
|
||||
[anchor, destroyHandler] = []
|
||||
|
||||
beforeEach ->
|
||||
destroyHandler = jasmine.createSpy("destroyHandler")
|
||||
anchor = editSession.addAnchorAtBufferPosition([4, 25])
|
||||
anchor.on 'destroy', destroyHandler
|
||||
|
||||
describe "when a buffer change precedes an anchor", ->
|
||||
it "moves the anchor in accordance with the change", ->
|
||||
editSession.setSelectedBufferRange([[3, 0], [4, 10]])
|
||||
editSession.delete()
|
||||
expect(anchor.getBufferPosition()).toEqual [3, 15]
|
||||
expect(destroyHandler).not.toHaveBeenCalled()
|
||||
|
||||
describe "when a buffer change surrounds an anchor", ->
|
||||
it "destroys the anchor", ->
|
||||
editSession.setSelectedBufferRange([[3, 0], [5, 0]])
|
||||
editSession.delete()
|
||||
expect(destroyHandler).toHaveBeenCalled()
|
||||
expect(editSession.getAnchors().indexOf(anchor)).toBe -1
|
||||
|
||||
describe ".clipBufferPosition(bufferPosition)", ->
|
||||
it "clips the given position to a valid position", ->
|
||||
expect(editSession.clipBufferPosition([-1, -1])).toEqual [0,0]
|
||||
|
||||
@@ -15,6 +15,10 @@ class Anchor
|
||||
{ oldRange, newRange } = e
|
||||
position = @getBufferPosition()
|
||||
|
||||
if oldRange.containsPoint(position, exclusive: true)
|
||||
@destroy()
|
||||
return
|
||||
|
||||
if @ignoreEqual
|
||||
return if position.isLessThanOrEqual(oldRange.end)
|
||||
else
|
||||
@@ -62,7 +66,8 @@ class Anchor
|
||||
@setScreenPosition(screenPosition, bufferChange: options.bufferChange, clip: false, assignBufferPosition: false)
|
||||
|
||||
destroy: ->
|
||||
@off()
|
||||
@editSession.removeAnchor(this)
|
||||
@trigger 'destroy'
|
||||
@off()
|
||||
|
||||
_.extend(Anchor.prototype, EventEmitter)
|
||||
|
||||
@@ -49,9 +49,12 @@ class Range
|
||||
else
|
||||
otherRange.intersectsWith(this)
|
||||
|
||||
containsPoint: (point) ->
|
||||
containsPoint: (point, { exclusive } = {}) ->
|
||||
point = Point.fromObject(point)
|
||||
point.isGreaterThanOrEqual(@start) and point.isLessThanOrEqual(@end)
|
||||
if exclusive
|
||||
point.isGreaterThan(@start) and point.isLessThan(@end)
|
||||
else
|
||||
point.isGreaterThanOrEqual(@start) and point.isLessThanOrEqual(@end)
|
||||
|
||||
containsRow: (row) ->
|
||||
@start.row <= row <= @end.row
|
||||
|
||||
Reference in New Issue
Block a user