The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 00:45 UTC
fix(web): scrolling pans expanded images and Mermaid diagrams (#26630)
Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
shivam committed
Nov 10, 2026 at 07:41 UTC
046efd791efb5f81f9f6d5e03f4336d3436e4293
2 files changed
+74
-4
apps/web/src/components/chat/ExpandedImageDialog.browser.test.tsx
+69
@@ -79,4 +79,73 @@ describe("ExpandedImageDialog", () => {
79
await userEvent.keyboard("{Escape}");
80
await vi.waitFor(() => expect(onClose).toHaveBeenCalledOnce());
81
});
82
+
83
+ it("scrolling pans the image while Ctrl+wheel zooms around the pointer", async () => {
84
+ const canvas = document.createElement("canvas");
85
+ canvas.width = 1600;
86
+ canvas.height = 1200;
87
+ await using screen = await render(
88
+ <ExpandedImageDialog
89
+ preview={{ images: [{ src: canvas.toDataURL(), name: "large.png" }], index: 0 }}
90
+ onClose={() => {}}
91
+ />,
92
+ // The dialog renders no links and reads no route.
93
+ { router: false },
94
+ );
95
+ const viewportLocator = screen.getByRole("region", { name: "large.png, zoomable image" });
96
+ const viewport = viewportLocator.element() as HTMLElement;
97
+ const image = screen.getByRole("img", { name: "large.png" }).element() as HTMLElement;
98
+ await vi.waitFor(() => expect(image.style.width).not.toBe(""));
99
+ const fitWidth = image.getBoundingClientRect().width;
100
+ const wheels: { ctrlKey: boolean; canceled: boolean }[] = [];
101
+ const recordWheel = (event: WheelEvent) =>
102
+ wheels.push({ ctrlKey: event.ctrlKey, canceled: event.defaultPrevented });
103
+ document.addEventListener("wheel", recordWheel);
104
+ using _wheelListener = {
105
+ [Symbol.dispose]: () => document.removeEventListener("wheel", recordWheel),
106
+ };
107
+ // Wheels land on the viewport's center; this is the image fraction under it.
108
+ const pointerFraction = () => {
109
+ const viewportBounds = viewport.getBoundingClientRect();
110
+ const imageBounds = image.getBoundingClientRect();
111
+ return {
112
+ x: (viewportBounds.left + viewportBounds.width / 2 - imageBounds.left) / imageBounds.width,
113
+ y: (viewportBounds.top + viewportBounds.height / 2 - imageBounds.top) / imageBounds.height,
114
+ };
115
+ };
116
+ const ctrlWheel = async (deltaY: number) => {
117
+ await userEvent.keyboard("{Control>}");
118
+ await userEvent.wheel(viewportLocator, { delta: { y: deltaY } });
119
+ await userEvent.keyboard("{/Control}");
120
+ };
121
+
122
+ await userEvent.wheel(viewportLocator, { delta: { y: 120 } });
123
+ expect(wheels.at(-1)).toEqual({ ctrlKey: false, canceled: false });
124
+ expect(image.getBoundingClientRect().width).toBe(fitWidth);
125
+
126
+ await ctrlWheel(-100);
127
+ expect(wheels.at(-1)).toEqual({ ctrlKey: true, canceled: true });
128
+ const zoomedWidth = image.getBoundingClientRect().width;
129
+ expect(zoomedWidth).toBeCloseTo(fitWidth * Math.E, 0);
130
+
131
+ const pan = async (delta: { x: number; y: number }) => {
132
+ const { scrollLeft, scrollTop } = viewport;
133
+ await userEvent.wheel(viewportLocator, { delta });
134
+ await vi.waitFor(() => {
135
+ expect(Math.sign(viewport.scrollLeft - scrollLeft)).toBe(Math.sign(delta.x));
136
+ expect(Math.sign(viewport.scrollTop - scrollTop)).toBe(Math.sign(delta.y));
137
+ });
138
+ };
139
+ await pan({ x: 60, y: 0 });
140
+ await pan({ x: 0, y: 60 });
141
+ await pan({ x: -40, y: -40 });
142
+ expect(wheels.filter((wheel) => !wheel.ctrlKey).every((wheel) => !wheel.canceled)).toBe(true);
143
+ expect(image.getBoundingClientRect().width).toBe(zoomedWidth);
144
+
145
+ const anchor = pointerFraction();
146
+ await ctrlWheel(-50);
147
+ expect(image.getBoundingClientRect().width).toBeGreaterThan(zoomedWidth);
148
+ expect(pointerFraction().x).toBeCloseTo(anchor.x, 2);
149
+ expect(pointerFraction().y).toBeCloseTo(anchor.y, 2);
150
+ });
151
});
apps/web/src/components/chat/ZoomableImage.tsx
+5
-4
@@ -134,14 +134,15 @@ export function ZoomableImage({
134
135
const attachViewport = (viewport: HTMLDivElement) => {
136
viewportRef.current = viewport;
137
- // React's onWheel is passive and cannot stop the page from scrolling.
137
+ // Trackpad pinch arrives as a ctrlKey wheel; plain wheels pan through native overflow scrolling.
138
+ // React's onWheel is passive and cannot stop the browser's own page zoom.
139
const wheel = (event: WheelEvent) => {
139
- if (event.deltaY === 0) return;
140
+ if (!event.ctrlKey || event.deltaY === 0) return;
141
event.preventDefault();
142
const delta =
143
event.deltaY *
144
(event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? viewport.clientHeight : 1);
144
- changeZoom(zoom * Math.exp(-delta * (event.ctrlKey ? 0.01 : 0.002)), {
145
+ changeZoom(zoom * Math.exp(-delta * 0.01), {
146
x: event.clientX,
147
y: event.clientY,
148
});
@@ -159,7 +160,7 @@ export function ZoomableImage({
160
ref={attachViewport}
161
role="region"
162
aria-label={`${name}, zoomable image`}
162
- aria-description="Click to zoom in or return to fit. Scroll to zoom, drag to pan. Use Enter to toggle zoom, plus or minus to zoom, and 0 to fit."
163
+ aria-description="Click to zoom in or return to fit. Pinch or Ctrl+scroll to zoom, scroll or drag to pan. Use Enter to toggle zoom, plus or minus to zoom, and 0 to fit."
164
tabIndex={0}
165
className="max-w-[var(--media-width)] overflow-auto overscroll-contain rounded-lg bg-background shadow-2xl ring-1 ring-border/70 outline-none focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-ring"
166
style={{