diff --git a/packages/editor/src/extensions/search-replace/search-replace.ts b/packages/editor/src/extensions/search-replace/search-replace.ts index 6acf330ef..02eaec305 100644 --- a/packages/editor/src/extensions/search-replace/search-replace.ts +++ b/packages/editor/src/extensions/search-replace/search-replace.ts @@ -28,6 +28,7 @@ import { } from "prosemirror-state"; import { SearchSettings } from "../../toolbar/stores/search-store.js"; import { tiptapKeys } from "@notesnook/common"; +import { findParentNodeClosestToPos } from "../../utils/prosemirror.js"; type DispatchFn = (tr: Transaction) => void; declare module "@tiptap/core" { @@ -295,6 +296,8 @@ export const SearchReplace = Extension.create({ ) ); + expandCollapsedCallout(tr, from); + const domNode = this.editor.view.domAtPos(from).node; scrollIntoView(domNode); @@ -322,6 +325,8 @@ export const SearchReplace = Extension.create({ ) ); + expandCollapsedCallout(tr, from); + const domNode = this.editor.view.domAtPos(from).node; scrollIntoView(domNode); @@ -476,6 +481,18 @@ export const SearchReplace = Extension.create({ } }); +function expandCollapsedCallout(tr: Transaction, pos: number) { + const $pos = tr.doc.resolve(pos); + const calloutParent = findParentNodeClosestToPos( + $pos, + (node) => node.type.name === "callout" + ); + if (!calloutParent || !calloutParent.node.attrs.collapsed) return; + + tr.setMeta("preventSave", true); + tr.setNodeAttribute(calloutParent.pos, "collapsed", false); +} + function scrollIntoView(domNode: Node) { setTimeout(() => { if ("scrollIntoView" in domNode) {