Add startRow and endRow special attributes to TextBuffer.findMarker[s]

This commit is contained in:
Nathan Sobo
2013-04-24 17:22:37 -06:00
parent 4a764c2d9d
commit 64aaf670ed
3 changed files with 17 additions and 1 deletions

View File

@@ -966,6 +966,11 @@ describe 'Buffer', ->
it "returns the markers matching the given attributes, sorted by the buffer location and size of their ranges", ->
expect(buffer.findMarkers(class: 'a')).toEqual [marker2, marker1, marker3]
it "allows the startRow and endRow to be specified", ->
expect(buffer.findMarkers(class: 'a', startRow: 0)).toEqual [marker2, marker1]
expect(buffer.findMarkers(class: 'a', startRow: 0, endRow: 3)).toEqual [marker1]
expect(buffer.findMarkers(endRow: 10)).toEqual [marker4]
describe "marker destruction", ->
marker = null

View File

@@ -50,7 +50,13 @@ class BufferMarker
# Returns a {Boolean}.
matchesAttributes: (queryAttributes) ->
for key, value of queryAttributes
return false unless _.isEqual(@attributes[key], value)
switch key
when 'startRow'
return false unless @getRange().start.row == value
when 'endRow'
return false unless @getRange().end.row == value
else
return false unless _.isEqual(@attributes[key], value)
true
# Public: Identifies if the marker's head position is equal to its tail.

View File

@@ -434,6 +434,11 @@ class Buffer
# Public: Finds all markers satisfying the given attributes
#
# attributes - The attributes against which to compare the markers' attributes
# There are some reserved keys that match against derived marker properties:
# startRow - The row at which the marker starts
# endRow - The row at which the marker ends
#
# Returns an {Array} of {String} marker-identifiers
findMarkers: (attributes) ->
markers = @getMarkers().filter (marker) -> marker.matchesAttributes(attributes)