diff --git a/packages/codemirror/src/find_replace.ts b/packages/codemirror/src/find_replace.ts index 857b572b3..b006ad015 100644 --- a/packages/codemirror/src/find_replace.ts +++ b/packages/codemirror/src/find_replace.ts @@ -19,10 +19,15 @@ export class SearchHighlighter { this.parsedMatches = []; this.currentFound = 0; this.totalFound = 0; - this.matches = (new RangeSetBuilder()).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" : "";