editor: expand callout on search scroll if search text inside callout

Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
01zulfi
2026-04-21 14:24:41 +05:00
committed by Abdullah Atta
parent a4c8259a02
commit 5fbfbb7a87

View File

@@ -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<SearchOptions, SearchStorage>({
)
);
expandCollapsedCallout(tr, from);
const domNode = this.editor.view.domAtPos(from).node;
scrollIntoView(domNode);
@@ -322,6 +325,8 @@ export const SearchReplace = Extension.create<SearchOptions, SearchStorage>({
)
);
expandCollapsedCallout(tr, from);
const domNode = this.editor.view.domAtPos(from).node;
scrollIntoView(domNode);
@@ -476,6 +481,18 @@ export const SearchReplace = Extension.create<SearchOptions, SearchStorage>({
}
});
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) {