From 64aaf670ed1ef8747cc857c5452642dccec0b4df Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 24 Apr 2013 17:22:37 -0600 Subject: [PATCH] Add startRow and endRow special attributes to TextBuffer.findMarker[s] --- spec/app/text-buffer-spec.coffee | 5 +++++ src/app/buffer-marker.coffee | 8 +++++++- src/app/text-buffer.coffee | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/spec/app/text-buffer-spec.coffee b/spec/app/text-buffer-spec.coffee index 24ea47045..7636523b0 100644 --- a/spec/app/text-buffer-spec.coffee +++ b/spec/app/text-buffer-spec.coffee @@ -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 diff --git a/src/app/buffer-marker.coffee b/src/app/buffer-marker.coffee index 7090328cb..fdcb9f7fc 100644 --- a/src/app/buffer-marker.coffee +++ b/src/app/buffer-marker.coffee @@ -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. diff --git a/src/app/text-buffer.coffee b/src/app/text-buffer.coffee index 5363c13c8..c94d78075 100644 --- a/src/app/text-buffer.coffee +++ b/src/app/text-buffer.coffee @@ -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)