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(mermaid): not recentering when using the sample switcher
Elian Dorandce9f5091184
diff --git a/apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsx b/apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsxindex ac0a44f9a7..d0043f9784 100644--- a/apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsx+++ b/apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsx@@ -152,6 +152,7 @@ export default function SvgSplitEditor({ ntxId, note, attachmentName, renderSvg,function useResizer(containerRef: RefObject<HTMLDivElement>, noteId: string, svg: string | undefined) {const lastPanZoom = useRef<{ pan: SvgPanZoom.Point, zoom: number }>();const lastNoteId = useRef<string>();+ const wasEmpty = useRef<boolean>(false);const zoomRef = useRef<SvgPanZoom.Instance>();const width = useElementSize(containerRef);@@ -159,9 +160,14 @@ function useResizer(containerRef: RefObject<HTMLDivElement>, noteId: string, svguseEffect(() => {if (zoomRef.current || width?.width === 0) return;- const shouldPreservePanZoom = (lastNoteId.current === noteId);+ const shouldPreservePanZoom = (lastNoteId.current === noteId) && !wasEmpty.current;const svgEl = containerRef.current?.querySelector("svg");- if (!svgEl) return;+ if (!svgEl) {+ if (svg?.trim().length === 0) {+ wasEmpty.current = true;+ }+ return;+ };const zoomInstance = svgPanZoom(svgEl, {zoomEnabled: true,@@ -187,7 +193,7 @@ function useResizer(containerRef: RefObject<HTMLDivElement>, noteId: string, svgzoomRef.current = undefined;zoomInstance.destroy();};- }, [ svg, width ]);+ }, [ containerRef, noteId, svg, width ]);// React to container changes.useEffect(() => {