mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-02 04:01:43 +02:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user