Skip to content

The agent that grows with you

fix(desktop): inset the zoom overlay fit so wide content doesn't touch the edges

Brooklyn Nicholson88486b222aef
diff --git a/apps/desktop/src/components/ui/use-zoom-pan.ts b/apps/desktop/src/components/ui/use-zoom-pan.ts
index cbe6b744989..fa305883d68 100644
--- a/apps/desktop/src/components/ui/use-zoom-pan.ts
+++ b/apps/desktop/src/components/ui/use-zoom-pan.ts
@@ -20,6 +20,10 @@ const MIN_SCALE = 0.25
const MAX_SCALE = 8
const WHEEL_STEP = 1.1
const BUTTON_STEP = 1.25
+// Breathing room around fitted content. Vertical clears the floating toolbar
+// at the stage's bottom edge; symmetric so the grid centering stays exact.
+const FIT_INSET_X = 32
+const FIT_INSET_Y = 64
// A fitted diagram can shrink far below the interactive zoom-out floor, so
// surfaces that fit content (see `setContentEl`) pass this via `minScale`.
export const FIT_MIN_SCALE = 0.05
@@ -94,17 +98,18 @@ export function useZoomPan<T extends HTMLElement = HTMLElement>(options: UseZoom
[clamp]
)
- // Shrink the content so it fits the stage, never upscale it. The stage grid
- // centers the content, so the fit transform needs no translation. Content
- // with no measurable size yet (async render, e.g. mermaid) stays as-is — a
- // zero scale would blank the overlay instead of waiting for geometry.
+ // Shrink the content so it fits the stage, inset from its edges, and never
+ // upscale it. The stage grid centers the content, so the fit transform needs
+ // no translation. Content with no measurable size yet (async render, e.g.
+ // mermaid) stays as-is — a zero scale would blank the overlay instead of
+ // waiting for geometry.
const fit = useCallback(() => {
if (!node || !contentEl) {
return
}
- const availableW = node.clientWidth
- const availableH = node.clientHeight
+ const availableW = node.clientWidth - FIT_INSET_X * 2
+ const availableH = node.clientHeight - FIT_INSET_Y * 2
const contentW = contentEl.scrollWidth
const contentH = contentEl.scrollHeight
@@ -173,7 +178,10 @@ export function useZoomPan<T extends HTMLElement = HTMLElement>(options: UseZoom
// Native, non-passive wheel so we can preventDefault page scroll. Attached to
// the surface node (ref) only while the viewer is enabled, so it never
- // hijacks wheel events when the lightbox/dialog is closed.
+ // hijacks wheel events when the lightbox/dialog is closed. The handler's
+ // `fittedRef.current = false` is not an atom-mirror — a one-way gesture flag
+ // marking the view as manually zoomed.
+ // eslint-disable-next-line no-restricted-syntax
useEffect(() => {
if (!node || !enabled) {
return
diff --git a/apps/desktop/src/components/ui/zoomable-fit.test.tsx b/apps/desktop/src/components/ui/zoomable-fit.test.tsx
index 7948ce6c9ee..d4b6f6ae47a 100644
--- a/apps/desktop/src/components/ui/zoomable-fit.test.tsx
+++ b/apps/desktop/src/components/ui/zoomable-fit.test.tsx
@@ -86,9 +86,10 @@ describe('Zoomable overlay fit', () => {
FakeResizeObserver.deliver()
})
- // 1000/4758 ≈ 0.2102 — below the old MIN_SCALE floor of 0.25, so this
+ // The 1000×600 stage minus its 32px/64px fit insets leaves 936×472, so
+ // 936/4758 ≈ 0.197 — below the old MIN_SCALE floor of 0.25, so this
// also pins the lower clamp.
- expect(content.style.transform).toBe('translate(0px, 0px) scale(0.2101723413198823)')
+ expect(content.style.transform).toBe(`translate(0px, 0px) scale(${936 / 4758})`)
})
it('does not scale content that already fits beyond 100%', () => {
@@ -154,10 +155,10 @@ describe('Zoomable overlay fit', () => {
})
fireEvent.click(screen.getByRole('button', { name: 'Zoom in' }))
- expect(content.style.transform).not.toBe('translate(0px, 0px) scale(0.2101723413198823)')
+ expect(content.style.transform).not.toBe(`translate(0px, 0px) scale(${936 / 4758})`)
fireEvent.click(screen.getByRole('button', { name: 'Reset' }))
- expect(content.style.transform).toBe('translate(0px, 0px) scale(0.2101723413198823)')
+ expect(content.style.transform).toBe(`translate(0px, 0px) scale(${936 / 4758})`)
// After reset the view is the fitted one again, so a later geometry
// change must re-fit rather than leave the reset scale behind.
@@ -166,7 +167,7 @@ describe('Zoomable overlay fit', () => {
FakeResizeObserver.deliver()
})
- expect(content.style.transform).toBe('translate(0px, 0px) scale(0.4203446826397646)')
+ expect(content.style.transform).toBe(`translate(0px, 0px) scale(${936 / 2379})`)
})
it('keeps the fitted view tracking later geometry changes', () => {
@@ -194,6 +195,6 @@ describe('Zoomable overlay fit', () => {
FakeResizeObserver.deliver()
})
- expect(content.style.transform).toBe('translate(0px, 0px) scale(0.4203446826397646)')
+ expect(content.style.transform).toBe(`translate(0px, 0px) scale(${936 / 2379})`)
})
})