Skip to content

Commit

Permalink
fix: make zoomToFit fitToViewport account for sidebar (excalidraw#7298)
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasmolnar committed Nov 17, 2023
1 parent 1e37dbd commit 7c9cf30
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/actions/actionCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit 7c9cf30

Please sign in to comment.