From 7c9cf30909c6c368407994cb25e22292b99eee5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20Moln=C3=A1r?= <38168628+barnabasmolnar@users.noreply.github.com> Date: Fri, 17 Nov 2023 15:56:19 +0100 Subject: [PATCH] fix: make zoomToFit fitToViewport account for sidebar (#7298) --- src/actions/actionCanvas.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/actions/actionCanvas.tsx b/src/actions/actionCanvas.tsx index 2194f63b..f61f57db 100644 --- a/src/actions/actionCanvas.tsx +++ b/src/actions/actionCanvas.tsx @@ -265,7 +265,21 @@ export const zoomToFit = ({ 30.0, ) as NormalizedZoomValue; - scrollX = (appState.width / 2) * (1 / newZoomValue) - centerX; + let appStateWidth = appState.width; + + if (appState.openSidebar) { + const sidebarDOMElem = document.querySelector( + ".sidebar", + ) as HTMLElement | null; + const sidebarWidth = sidebarDOMElem?.offsetWidth ?? 0; + const isRTL = document.documentElement.getAttribute("dir") === "rtl"; + + appStateWidth = !isRTL + ? appState.width - sidebarWidth + : appState.width + sidebarWidth; + } + + scrollX = (appStateWidth / 2) * (1 / newZoomValue) - centerX; scrollY = (appState.height / 2) * (1 / newZoomValue) - centerY; } else { newZoomValue = zoomValueToFitBoundsOnViewport(commonBounds, {