Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(codemirror): search not unfolding results
Elian Doran03de472a575c
diff --git a/packages/codemirror/src/find_replace.ts b/packages/codemirror/src/find_replace.tsindex ba9347cfe1..40d3c15a7c 100644--- a/packages/codemirror/src/find_replace.ts+++ b/packages/codemirror/src/find_replace.ts@@ -1,5 +1,6 @@import { EditorView, Decoration, MatchDecorator, ViewPlugin, ViewUpdate } from "@codemirror/view";-import { Range, RangeSet } from "@codemirror/state";+import { foldState, unfoldEffect } from "@codemirror/language";+import { Range, RangeSet, StateEffect } from "@codemirror/state";const searchMatchDecoration = Decoration.mark({ class: "cm-searchMatch" });const activeMatchDecoration = Decoration.mark({ class: "cm-activeMatch" });@@ -79,8 +80,23 @@ export class SearchHighlighter {const match = this.parsedMatches[matchIndex];this.currentFound = matchIndex + 1;this.activeMatch = activeMatchDecoration.range(match.from, match.to);++ // Check if the match is inside a folded region.+ const unfoldEffects: StateEffect<unknown>[] = [];+ const folded = this.view.state.field(foldState);+ const iter = folded.iter();+ while (iter.value) {+ if (match.from >= iter.from && match.to <= iter.to) {+ unfoldEffects.push(unfoldEffect.of({ from: iter.from, to: iter.to }));+ }+ iter.next();+ }+this.view.dispatch({- effects: EditorView.scrollIntoView(match.from, { y: "center" }),+ effects: [+ ...unfoldEffects,+ EditorView.scrollIntoView(match.from, { y: "center" })+ ],scrollIntoView: true});}diff --git a/packages/codemirror/src/index.ts b/packages/codemirror/src/index.tsindex 8d6687be86..c86d37b12d 100644--- a/packages/codemirror/src/index.ts+++ b/packages/codemirror/src/index.ts@@ -1,6 +1,6 @@import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";import { EditorView, highlightActiveLine, keymap, lineNumbers, placeholder, ViewPlugin, ViewUpdate, type EditorViewConfig } from "@codemirror/view";-import { defaultHighlightStyle, StreamLanguage, syntaxHighlighting, indentUnit, bracketMatching, foldGutter } from "@codemirror/language";+import { defaultHighlightStyle, StreamLanguage, syntaxHighlighting, indentUnit, bracketMatching, foldGutter, codeFolding } from "@codemirror/language";import { Compartment, EditorSelection, EditorState, type Extension } from "@codemirror/state";import { highlightSelectionMatches } from "@codemirror/search";import { vim } from "@replit/codemirror-vim";@@ -73,6 +73,7 @@ export default class CodeMirror extends EditorView {]),highlightSelectionMatches(),bracketMatching(),+ codeFolding(),foldGutter(),indentationMarkers(),];