Add DisplayBuffer.findMarker[s]

This commit is contained in:
Nathan Sobo
2013-04-24 18:10:16 -06:00
parent ac90b13032
commit e02e4cd975
2 changed files with 20 additions and 0 deletions

View File

@@ -726,6 +726,16 @@ describe "DisplayBuffer", ->
expect(changeHandler).toHaveBeenCalled()
expect(observeHandler).toHaveBeenCalled()
describe ".findMarkers(attributes)", ->
it "allows the startBufferRow and endBufferRow to be specified", ->
marker1 = displayBuffer.markBufferRange([[0, 0], [3, 0]], class: 'a')
marker2 = displayBuffer.markBufferRange([[0, 0], [5, 0]], class: 'a')
marker3 = displayBuffer.markBufferRange([[9, 0], [10, 0]], class: 'b')
expect(displayBuffer.findMarkers(class: 'a', startBufferRow: 0)).toEqual [marker2, marker1]
expect(displayBuffer.findMarkers(class: 'a', startBufferRow: 0, endBufferRow: 3)).toEqual [marker1]
expect(displayBuffer.findMarkers(endBufferRow: 10)).toEqual [marker3]
describe "marker destruction", ->
it "allows markers to be destroyed", ->
marker = displayBuffer.markScreenRange([[5, 4], [5, 10]])

View File

@@ -673,6 +673,16 @@ class DisplayBuffer
observeMarker: (id, callback) ->
@getMarker(id).observe(callback)
findMarker: (attributes) ->
@findMarkers(attributes)[0]
findMarkers: (attributes) ->
{ startBufferRow, endBufferRow } = attributes
attributes.startRow = startBufferRow if startBufferRow?
attributes.endRow = endBufferRow if endBufferRow?
attributes = _.omit(attributes, ['startBufferRow', 'endBufferRow'])
@buffer.findMarkers(attributes)
###
# Internal #
###