diff --git a/packages/app/e2e/regression/review.spec.ts b/packages/app/e2e/regression/review.spec.ts
index c4e05a77854..3cda71ebf96 100644
--- a/packages/app/e2e/regression/review.spec.ts
+++ b/packages/app/e2e/regression/review.spec.ts
@@ -86,7 +86,9 @@ test("Git initialization belongs to its session and refreshes after a session sw
await expect(pending).toHaveCount(0)
})
-test("a rejected Git init releases its session's button without showing an error in another session", async ({ page }) => {
+test("a rejected Git init releases its session's button without showing an error in another session", async ({
+ page,
+}) => {
await openSession(page, {
name: "ReviewInitFailure",
project: { vcs: undefined },
@@ -498,6 +500,127 @@ test("rereads a file each time an artifact link opens it", async ({ page }) => {
/** What the image case's frame probe records on the window. */
type ImageProbe = { problems: string[]; frames: number; running: boolean }
+test("image gestures anchor zoom, pan, and reset independently of the pane", async ({ page }) => {
+ // Some browsers expose no natural dimensions for a viewBox-only SVG.
+ await page.addInitScript(() => {
+ for (const name of ["naturalWidth", "naturalHeight"]) {
+ const original = Object.getOwnPropertyDescriptor(HTMLImageElement.prototype, name)!
+ Object.defineProperty(HTMLImageElement.prototype, name, {
+ ...original,
+ get() {
+ return this.alt === "second.svg" ? 0 : original.get?.call(this)
+ },
+ })
+ }
+ })
+ await openSession(page, {
+ name: "ImageGestures",
+ fileList: () => [],
+ fileContent: (path) => ({
+ content:
+ path === "second.svg"
+ ? ''
+ : '',
+ }),
+ pageMessages: () => ({
+ items: [
+ {
+ id: "msg_images",
+ type: "assistant",
+ agent: "build",
+ model: { id: "test", providerID: "opencode" },
+ content: [{ type: "text", text: "[First](first.svg) [Second](second.svg)" }],
+ time: { created: 1, completed: 2 },
+ },
+ ],
+ }),
+ })
+ await page.getByRole("link", { name: "First", exact: true }).click()
+ const panel = page.locator("#review-panel")
+ const image = panel.getByRole("img", { name: "first.svg", exact: true })
+ const stage = panel.locator('[data-slot="artifact-stage"]')
+ const fit = panel.getByRole("button", { name: "Fit", exact: true })
+ await expect(image).toBeVisible()
+ await expect(fit).toBeDisabled()
+ // Wait for the side pane's opening motion before choosing a gesture anchor.
+ await image.hover()
+ const initial = (await image.boundingBox())!
+ const pane = (await panel.boundingBox())!
+ const anchor = { x: Math.round(initial.x + initial.width * 0.55), y: Math.round(initial.y + initial.height * 0.55) }
+ await page.mouse.move(anchor.x, anchor.y)
+ // A continuous pinch catches anchor drift while the image still fits one axis.
+ const cdp = await page.context().newCDPSession(page)
+ await cdp.send("Input.synthesizePinchGesture", {
+ ...anchor,
+ scaleFactor: 2,
+ relativeSpeed: 500,
+ gestureSourceType: "mouse",
+ })
+ await cdp.detach()
+ await expect(fit).toBeEnabled()
+ const zoomed = (await image.boundingBox())!
+ expect(zoomed.width).toBeCloseTo(initial.width * 2, 1)
+ expect((anchor.x - zoomed.x) / zoomed.width).toBeCloseTo((anchor.x - initial.x) / initial.width, 4)
+ expect((anchor.y - zoomed.y) / zoomed.height).toBeCloseTo((anchor.y - initial.y) / initial.height, 4)
+ expect(await panel.boundingBox()).toEqual(pane)
+ expect(await page.evaluate(() => window.visualViewport?.scale)).toBe(1)
+ await page.mouse.wheel(40, 60)
+ await expect.poll(async () => (await image.boundingBox())!.x).toBeCloseTo(zoomed.x - 40, 1)
+ expect((await image.boundingBox())!.y).toBeCloseTo(zoomed.y - 60, 1)
+ const scrolled = (await image.boundingBox())!
+ await page.mouse.down()
+ await page.mouse.move(anchor.x + 60, anchor.y + 40, { steps: 5 })
+ await page.mouse.up()
+ await expect(fit).toBeEnabled()
+ expect((await image.boundingBox())!.x).toBeCloseTo(scrolled.x + 60, 1)
+ expect((await image.boundingBox())!.y).toBeCloseTo(scrolled.y + 40, 1)
+ // Touch uses the same captured-pointer path and must not generate a click-to-fit.
+ const touch = await page.context().newCDPSession(page)
+ await touch.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: [{ x: anchor.x, y: anchor.y }] })
+ await touch.send("Input.dispatchTouchEvent", {
+ type: "touchMove",
+ touchPoints: [{ x: anchor.x - 30, y: anchor.y - 20 }],
+ })
+ await touch.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] })
+ await touch.detach()
+ await expect(fit).toBeEnabled()
+ expect((await image.boundingBox())!.x).toBeCloseTo(scrolled.x + 30, 1)
+ expect((await image.boundingBox())!.y).toBeCloseTo(scrolled.y + 20, 1)
+ // Keyboard-accessible fit restores the exact original geometry.
+ await fit.focus()
+ await page.keyboard.press("Enter")
+ await expect(fit).toBeDisabled()
+ expect(await image.boundingBox()).toEqual(initial)
+ expect(
+ await stage.evaluate((element) =>
+ element.dispatchEvent(new WheelEvent("wheel", { deltaY: 40, bubbles: true, cancelable: true })),
+ ),
+ ).toBe(true)
+ await image.click()
+ await expect(fit).toBeEnabled()
+ await page.getByRole("link", { name: "Second", exact: true }).click()
+ await expect(panel.getByRole("img", { name: "second.svg", exact: true })).toBeVisible()
+ await expect(fit).toBeDisabled()
+ await panel.getByRole("img", { name: "second.svg", exact: true }).hover()
+ const second = (await panel.getByRole("img", { name: "second.svg", exact: true }).boundingBox())!
+ expect(second.width).toBeGreaterThan(0)
+ expect(second.height).toBeGreaterThan(0)
+ await page.keyboard.down("Control")
+ await page.mouse.wheel(0, -50)
+ await expect(fit).toBeEnabled()
+ await page.keyboard.up("Control")
+ await fit.click()
+ await page.setViewportSize({ width: 1200, height: 700 })
+ await expect
+ .poll(async () => {
+ const frame = (await stage.boundingBox())!
+ const media = (await panel.getByRole("img", { name: "second.svg", exact: true }).boundingBox())!
+
+ return media.width <= frame.width - 47 && media.height <= frame.height - 47
+ })
+ .toBe(true)
+})
+
test("image files load into the review panel and keep it painted while loading", async ({ page }) => {
await page.setViewportSize({ width: 960, height: 900 })
const directory = "C:/OpenCode/ReviewImage"
diff --git a/packages/gui-extensions/src/file/artifact-view.tsx b/packages/gui-extensions/src/file/artifact-view.tsx
index 2ed851d2b2d..e4e1efe8ad8 100644
--- a/packages/gui-extensions/src/file/artifact-view.tsx
+++ b/packages/gui-extensions/src/file/artifact-view.tsx
@@ -1,4 +1,15 @@
-import { createMemo, createSignal, ErrorBoundary, For, Match, onCleanup, Show, Switch, untrack, type JSX } from "solid-js"
+import {
+ createMemo,
+ createSignal,
+ ErrorBoundary,
+ For,
+ Match,
+ onCleanup,
+ Show,
+ Switch,
+ untrack,
+ type JSX,
+} from "solid-js"
import { createStore } from "solid-js/store"
import { Dynamic } from "solid-js/web"
import { makeEventListener } from "@solid-primitives/event-listener"
@@ -38,8 +49,6 @@ type ViewerState = {
readonly reason?: string
}
-type ImageZoom = { readonly url: string; readonly zoom: "fit" | "actual"; readonly overflow: boolean }
-
type MediaProps = {
path: string
content: FileContent
@@ -295,31 +304,92 @@ function createBlobUrl(content: () => FileContent) {
})
}
-/** Images and SVG previews: fit the pane, click to inspect at 1:1 when the image is larger. */
+/** Images and SVG previews: each decoded image owns its viewport. */
function ArtifactImage(props: MediaProps) {
const url = createBlobUrl(() => props.content)
- const [size, setSize] = createStore({ width: 0, height: 0 })
- // Zoom belongs to one image: a new one starts fitted.
- const fitted = (): ImageZoom => ({ url: url(), zoom: "fit", overflow: false })
- const [saved, setSaved] = createSignal(fitted())
- const state = () => {
- const value = saved()
+ return (
+