Skip to content

Commit 9de3e54

Browse files
committed
Add a findMarks method
Closes #2200
1 parent 997ab42 commit 9de3e54

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

doc/manual.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,9 @@ <h3 id="api_marker">Text-marking methods</h3>
12931293
to the left instead.</dd>
12941294
</dl></dd>
12951295

1296+
<dt id="findMarks"><code><strong>doc.findMarks</strong>(from: {line, ch}, to: {line, ch}) → array&lt;TextMarker&gt;</code></dt>
1297+
<dd>Returns an array of all the bookmarks and marked ranges
1298+
found between the given positions.</dd>
12961299
<dt id="findMarksAt"><code><strong>doc.findMarksAt</strong>(pos: {line, ch}) → array&lt;TextMarker&gt;</code></dt>
12971300
<dd>Returns an array of all the bookmarks and marked ranges
12981301
present at the given position.</dd>

lib/codemirror.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5072,6 +5072,22 @@ window.CodeMirror = (function() {
50725072
}
50735073
return markers;
50745074
},
5075+
findMarks: function(from, to) {
5076+
from = clipPos(this, from); to = clipPos(this, to);
5077+
var found = [], lineNo = from.line;
5078+
this.iter(from.line, to.line + 1, function(line) {
5079+
var spans = line.markedSpans;
5080+
if (spans) for (var i = 0; i < spans.length; i++) {
5081+
var span = spans[i];
5082+
if (!(lineNo == from.line && from.ch > span.to ||
5083+
span.from == null && lineNo != from.line||
5084+
lineNo == to.line && span.from > to.ch))
5085+
found.push(span.marker.parent || span.marker);
5086+
}
5087+
++lineNo;
5088+
});
5089+
return found;
5090+
},
50755091
getAllMarks: function() {
50765092
var markers = [];
50775093
this.iter(function(line) {

0 commit comments

Comments
 (0)