The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): attach lightbox wheel listener after portal mount; move zoom controls into the dialog chrome
Brooklyn Nicholson01cff226de28
diff --git a/apps/desktop/src/components/chat/zoomable-image.test.tsx b/apps/desktop/src/components/chat/zoomable-image.test.tsxindex 55556f78fc5..519f0766132 100644--- a/apps/desktop/src/components/chat/zoomable-image.test.tsx+++ b/apps/desktop/src/components/chat/zoomable-image.test.tsx@@ -97,7 +97,7 @@ describe('ZoomableImage lightbox', () => {await act(async () => {fireEvent.click(zoomIn)})- expect(percentageText()).toBe('130%')+ expect(percentageText()).toBe('125%')await act(async () => {fireEvent.click(reset)@@ -107,8 +107,8 @@ describe('ZoomableImage lightbox', () => {await act(async () => {fireEvent.click(zoomOut)})- // 1 / 1.3 ≈ 0.769 → 77%- expect(percentageText()).toBe('77%')+ // 1 / 1.25 = 0.8 → 80%+ expect(percentageText()).toBe('80%')})it('pans after zoom but does not close the lightbox', async () => {@@ -119,7 +119,7 @@ describe('ZoomableImage lightbox', () => {await act(async () => {fireEvent.click(screen.getByRole('button', { name: /zoom in/i }))})- expect(scaleOf(img)).toBeCloseTo(1.3, 5)+ expect(scaleOf(img)).toBeCloseTo(1.25, 5)await act(async () => {fireEvent.pointerDown(img, { clientX: 10, clientY: 10, pointerId: 1 })@@ -185,7 +185,7 @@ describe('ZoomableImage lightbox', () => {await act(async () => {fireEvent.click(screen.getByRole('button', { name: /zoom in/i }))})- expect(scaleOf(img)).toBeCloseTo(1.3, 5)+ expect(scaleOf(img)).toBeCloseTo(1.25, 5)// Start a gesture with pointer 1, then the browser cancels it (e.g. it// steals the gesture for a scroll). Without cleanup the stale pointer@@ -209,7 +209,7 @@ describe('ZoomableImage lightbox', () => {})// Scale is unchanged (no pinch zoom), and the image panned the expected 60px.- expect(scaleOf(img)).toBeCloseTo(1.3, 5)+ expect(scaleOf(img)).toBeCloseTo(1.25, 5)expect(translateX(img)).toBeCloseTo(60, 5)})})diff --git a/apps/desktop/src/components/chat/zoomable-image.tsx b/apps/desktop/src/components/chat/zoomable-image.tsxindex 35fc43eeba9..cfdde7a8513 100644--- a/apps/desktop/src/components/chat/zoomable-image.tsx+++ b/apps/desktop/src/components/chat/zoomable-image.tsx@@ -136,6 +136,45 @@ export function ImageLightbox({className="w-auto max-h-[calc(100vh-12rem)] max-w-[calc(100vw-12rem)] border-0 bg-transparent shadow-none"overlayClassName="bg-black/60"showCloseButton={false}+ chrome={+ open && (+ <div+ className="fixed bottom-4 left-1/2 z-50 flex -translate-x-1/2 items-center gap-1 rounded-full border border-border/70 bg-background/85 p-1 shadow-lg backdrop-blur"+ onPointerDown={event => event.stopPropagation()}+ onClick={event => event.stopPropagation()}+ >+ <button+ aria-label={copy.zoomOut}+ className="grid size-8 place-items-center rounded-full text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50"+ disabled={scale <= 0.25}+ onClick={() => zoomOut()}+ title={copy.zoomOut}+ type="button"+ >+ <ZoomOut className="size-4" />+ </button>+ <button+ aria-label={copy.resetZoom}+ className="min-w-14 rounded-full px-2 text-center text-xs font-medium tabular-nums text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"+ onClick={() => reset()}+ title={copy.resetZoom}+ type="button"+ >+ {Math.round(scale * 100)}%+ </button>+ <button+ aria-label={copy.zoomIn}+ className="grid size-8 place-items-center rounded-full text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50"+ disabled={scale >= 8}+ onClick={() => zoomIn()}+ title={copy.zoomIn}+ type="button"+ >+ <ZoomIn className="size-4" />+ </button>+ </div>+ )+ }><div className="group/lightbox relative inline-block"><img@@ -158,47 +197,6 @@ export function ImageLightbox({/></div></DialogContent>-- {/* Zoom controls — fixed to the viewport so they stay put while the image- is panned/zoomed. stopPropagation keeps them from starting a pan or- closing the lightbox. Only mounted while the lightbox is open. */}- {open && (- <div- className="fixed bottom-4 left-1/2 z-50 flex -translate-x-1/2 items-center gap-1 rounded-full border border-border/70 bg-background/85 p-1 shadow-lg backdrop-blur"- onPointerDown={event => event.stopPropagation()}- onClick={event => event.stopPropagation()}- >- <button- aria-label={copy.zoomOut}- className="grid size-8 place-items-center rounded-full text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50"- disabled={scale <= 0.25}- onClick={() => zoomOut()}- title={copy.zoomOut}- type="button"- >- <ZoomOut className="size-4" />- </button>- <button- aria-label={copy.resetZoom}- className="min-w-14 rounded-full px-2 text-center text-xs font-medium tabular-nums text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"- onClick={() => reset()}- title={copy.resetZoom}- type="button"- >- {Math.round(scale * 100)}%- </button>- <button- aria-label={copy.zoomIn}- className="grid size-8 place-items-center rounded-full text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50"- disabled={scale >= 8}- onClick={() => zoomIn()}- title={copy.zoomIn}- type="button"- >- <ZoomIn className="size-4" />- </button>- </div>- )}</Dialog>)}diff --git a/apps/desktop/src/components/ui/use-zoom-pan.ts b/apps/desktop/src/components/ui/use-zoom-pan.tsindex 980214460a2..6d738f99633 100644--- a/apps/desktop/src/components/ui/use-zoom-pan.ts+++ b/apps/desktop/src/components/ui/use-zoom-pan.ts@@ -48,6 +48,16 @@ export function useZoomPan<T extends HTMLElement = HTMLElement>(options: UseZoomconst clamp = useCallback((scale: number) => Math.min(maxScale, Math.max(minScale, scale)), [minScale, maxScale])const ref = useRef<T>(null)+ // The surface node as state, not just a ref: the surface may mount AFTER+ // `enabled` flips (the lightbox img renders inside a dialog portal, a commit+ // later than the open flag). An effect keyed on [enabled] alone would capture+ // a null ref and never attach the native wheel listener. Re-rendering on+ // mount re-runs that effect with the node in hand.+ const [node, setNode] = useState<T | null>(null)+ const refCallback = useCallback((instance: T | null) => {+ ref.current = instance+ setNode(instance)+ }, [])const [transform, setTransform] = useState<Transform>({ scale: 1, x: 0, y: 0 })const [panning, setPanning] = useState(false)const [moved, setMoved] = useState(false)@@ -93,7 +103,6 @@ export function useZoomPan<T extends HTMLElement = HTMLElement>(options: UseZoom// the surface node (ref) only while the viewer is enabled, so it never// hijacks wheel events when the lightbox/dialog is closed.useEffect(() => {- const node = ref.currentif (!node || !enabled) {return}@@ -119,7 +128,7 @@ export function useZoomPan<T extends HTMLElement = HTMLElement>(options: UseZoomnode.addEventListener('wheel', onWheel, { passive: false })return () => node.removeEventListener('wheel', onWheel)- }, [enabled, zoomAt])+ }, [enabled, node, zoomAt])const endPan = useCallback(() => {drag.current = null@@ -245,7 +254,7 @@ export function useZoomPan<T extends HTMLElement = HTMLElement>(options: UseZoomreturn {moved,panning,- ref,+ ref: refCallback,reset,scale: transform.scale,stageProps: {diff --git a/locales/_keys.desktop.json b/locales/_keys.desktop.jsonindex 72388b2ed14..9e889ff36d6 100644--- a/locales/_keys.desktop.json+++ b/locales/_keys.desktop.json@@ -1420,6 +1420,7 @@"desktop.readOnlyTranscriptSendBlocked","desktop.readOnlyTranscriptTitle","desktop.regenerateFailed",+ "desktop.resetZoom","desktop.restartToSaveImages","desktop.restartToUseSaveImage","desktop.restored",@@ -1446,6 +1447,8 @@"desktop.yoloSystem","desktop.yoloTitle","desktop.yoloToggleFailed",+ "desktop.zoomIn",+ "desktop.zoomOut","errors.boundaryDesc","errors.boundaryDetails","errors.boundaryTitle",