mirror of
https://github.com/zadam/trilium.git
synced 2026-03-22 08:13:46 +01:00
fix(mermaid): not recentering when using the sample switcher
This commit is contained in:
parent
5f1486cf6a
commit
dce9f50911
@ -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, svg
|
||||
useEffect(() => {
|
||||
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, svg
|
||||
zoomRef.current = undefined;
|
||||
zoomInstance.destroy();
|
||||
};
|
||||
}, [ svg, width ]);
|
||||
}, [ containerRef, noteId, svg, width ]);
|
||||
|
||||
// React to container changes.
|
||||
useEffect(() => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user