fix(code/find): infinite loop when empty

This commit is contained in:
Elian Doran 2025-05-12 22:11:51 +03:00
parent 07a751c677
commit da6cb71c6a
No known key found for this signature in database

View File

@ -19,10 +19,15 @@ export class SearchHighlighter {
this.parsedMatches = [];
this.currentFound = 0;
this.totalFound = 0;
this.matches = (new RangeSetBuilder<Decoration>()).finish();
this.matches = RangeSet.empty;
}
searchFor(searchTerm: string, matchCase: boolean, wholeWord: boolean) {
if (!searchTerm) {
this.matches = RangeSet.empty;
return;
}
// Escape the search term for use in RegExp
const escapedTerm = searchTerm.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const wordBoundary = wholeWord ? "\\b" : "";