perf(addon-search): collect highlight matches in one search session

Add SearchEngine.collectMatches to initialize cache and regex once while
gathering matches, and use it from _highlightAllMatches instead of
repeated find() calls.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Daniel Imms
2026-05-25 19:06:23 -07:00
co-authored by Cursor
parent e5ffbe315a
commit 73c99a8412
2 changed files with 50 additions and 22 deletions
+1 -17
View File
@@ -133,23 +133,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon, ISearchAp
// new search, clear out the old decorations
this.clearDecorations(true);
const results: ISearchResult[] = [];
let prevResult: ISearchResult | undefined = undefined;
let result = this._engine.find(term, 0, 0, searchOptions);
while (result && (prevResult?.row !== result.row || prevResult?.col !== result.col)) {
if (results.length >= this._highlightLimit) {
break;
}
prevResult = result;
results.push(prevResult);
result = this._engine.find(
term,
prevResult.col + prevResult.term.length >= this._terminal.cols ? prevResult.row + 1 : prevResult.row,
prevResult.col + prevResult.term.length >= this._terminal.cols ? 0 : prevResult.col + 1,
searchOptions
);
}
const results = this._engine.collectMatches(term, searchOptions, this._highlightLimit);
this._resultTracker.updateResults(results, this._highlightLimit);
if (searchOptions.decorations) {