Write DisplayBuffer::findMarkers in terms of TextBuffer::findMarkers

This commit is contained in:
Corey Johnson & Nathan Sobo
2013-08-21 11:30:38 -06:00
committed by Nathan Sobo
parent 0e49582616
commit 03712392c9
2 changed files with 19 additions and 17 deletions

View File

@@ -157,21 +157,8 @@ class DisplayBufferMarker
@bufferMarker.setAttributes(attributes)
matchesAttributes: (attributes) ->
for key, value of attributes
return false unless @matchesAttribute(key, value)
true
matchesAttribute: (key, value) ->
switch key
when 'startBufferRow'
key = 'startRow'
when 'endBufferRow'
key = 'endRow'
when 'containsBufferRange'
key = 'containsRange'
when 'containsBufferPosition'
key = 'containsPosition'
@bufferMarker.matchesAttribute(key, value)
attributes = @displayBuffer.translateToStringMarkerAttributes(attributes)
@bufferMarker.matchesAttributes(attributes)
# Destroys the marker
destroy: ->

View File

@@ -509,8 +509,23 @@ class DisplayBuffer
#
# Returns an {Array} of {DisplayBufferMarker}s
findMarkers: (attributes) ->
markers = @getMarkers().filter (marker) -> marker.matchesAttributes(attributes)
markers.sort (a, b) -> a.compare(b)
attributes = @translateToStringMarkerAttributes(attributes)
@buffer.findMarkers(attributes).map (stringMarker) => @getMarker(stringMarker.id)
translateToStringMarkerAttributes: (attributes) ->
stringMarkerAttributes = {}
for key, value of attributes
switch key
when 'startBufferRow'
key = 'startRow'
when 'endBufferRow'
key = 'endRow'
when 'containsBufferRange'
key = 'containsRange'
when 'containsBufferPosition'
key = 'containsPosition'
stringMarkerAttributes[key] = value
stringMarkerAttributes
findFoldMarker: (attributes) ->
@findFoldMarkers(attributes)[0]