Skip to content
Snippets Groups Projects
Commit 4fb97fee authored by Marijn Haverbeke's avatar Marijn Haverbeke
Browse files

[matchesonscrollbar addon] Support a maxMatches option

parent 9af92d9b
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@
function SearchAnnotation(cm, query, caseFold, options) {
this.cm = cm;
this.options = options;
var annotateOptions = {listenForChanges: false};
for (var prop in options) annotateOptions[prop] = options[prop];
if (!annotateOptions.className) annotateOptions.className = "CodeMirror-search-match";
......@@ -46,11 +47,12 @@
if (match.to.line >= this.gap.from) this.matches.splice(i--, 1);
}
var cursor = this.cm.getSearchCursor(this.query, CodeMirror.Pos(this.gap.from, 0), this.caseFold);
var maxMatches = this.options && this.options.maxMatches || MAX_MATCHES;
while (cursor.findNext()) {
var match = {from: cursor.from(), to: cursor.to()};
if (match.from.line >= this.gap.to) break;
this.matches.splice(i++, 0, match);
if (this.matches.length > MAX_MATCHES) break;
if (this.matches.length > maxMatches) break;
}
this.gap = null;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment