Skip to content

Build your personal knowledge base with Trilium Notes

fix(code/find): infinite loop when empty

Elian Doranda6cb71c6a82
diff --git a/packages/codemirror/src/find_replace.ts b/packages/codemirror/src/find_replace.ts
index 857b572b35..b006ad0151 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<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" : "";