mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Add Buffer.markersForPosition and coerce marker ids to strings
This commit is contained in:
@@ -928,6 +928,15 @@ describe 'Buffer', ->
|
||||
buffer.undo()
|
||||
expect(buffer.getMarkerRange(marker4)).toEqual [[4, 20], [4, 23]]
|
||||
|
||||
describe ".markersForPosition(position)", ->
|
||||
it "returns all markers that intersect the given position", ->
|
||||
m1 = buffer.markRange([[3, 4], [3, 10]])
|
||||
m2 = buffer.markRange([[3, 4], [3, 5]])
|
||||
m3 = buffer.markPosition([3, 5])
|
||||
expect(_.difference(buffer.markersForPosition([3, 5]), [m1, m2, m3]).length).toBe 0
|
||||
expect(_.difference(buffer.markersForPosition([3, 4]), [m1, m2]).length).toBe 0
|
||||
expect(_.difference(buffer.markersForPosition([3, 10]), [m1]).length).toBe 0
|
||||
|
||||
describe "anchors", ->
|
||||
[anchor, destroyHandler] = []
|
||||
|
||||
|
||||
@@ -121,6 +121,9 @@ class BufferMarker
|
||||
unobserve: (callback) ->
|
||||
_.remove(@observers, callback)
|
||||
|
||||
containsPoint: (point) ->
|
||||
@getRange().containsPoint(point)
|
||||
|
||||
notifyObservers: ({oldHeadPosition, newHeadPosition, oldTailPosition, newTailPosition, bufferChanged}) ->
|
||||
return if @suppressObserverNotification
|
||||
return if _.isEqual(newHeadPosition, oldHeadPosition) and _.isEqual(newTailPosition, oldTailPosition)
|
||||
|
||||
@@ -273,7 +273,7 @@ class Buffer
|
||||
|
||||
markRange: (range, options={}) ->
|
||||
marker = new BufferMarker(_.defaults({
|
||||
id: @nextMarkerId++
|
||||
id: (@nextMarkerId++).toString()
|
||||
buffer: this
|
||||
range
|
||||
}, options))
|
||||
@@ -323,6 +323,13 @@ class Buffer
|
||||
observeMarker: (id, callback) ->
|
||||
@validMarkers[id]?.observe(callback)
|
||||
|
||||
markersForPosition: (bufferPosition) ->
|
||||
bufferPosition = Point.fromObject(bufferPosition)
|
||||
ids = []
|
||||
for id, marker of @validMarkers
|
||||
ids.push(id) if marker.containsPoint(bufferPosition)
|
||||
ids
|
||||
|
||||
getAnchors: -> new Array(@anchors...)
|
||||
|
||||
addAnchor: (options) ->
|
||||
|
||||
Reference in New Issue
Block a user