fix(app): expand video previews into in-window theatre mode (#54696)

This commit is contained in:
Kit Langton
2026-10-12 00:32:12 -07:00
committed by GitHub
Unverified
parent d306a15cf6
commit 6d1be26251
4 changed files with 247 additions and 4 deletions
@@ -581,6 +581,73 @@ test("image files keep the review panel painted while loading", async ({ page })
).toEqual([])
})
test("video files expand into an in-window theatre overlay and collapse on Escape without remounting", async ({
page,
}) => {
const directory = "C:/OpenCode/ReviewVideo"
const file = "demo.webm"
const webm = Buffer.from(
"GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQJChYECGFOAZwEAAAAAAAH5EU2bdLpNu4tTq4QVSalmU6yBoU27i1OrhBZUrmtTrIHWTbuMU6uEElTDZ1OsggEyTbuMU6uEHFO7a1OsggHj7AEAAAAAAABZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmsCrXsYMPQkBNgIxMYXZmNjMuMS4xMDJXQYxMYXZmNjMuMS4xMDJEiYhAj0AAAAAAABZUrmvXrgEAAAAAAABO14EBc8WIiQeUklk95R2cgQAitZyDdW5kiIEAhoVWX1ZQOIOBASPjg4Q7msoA4JCwgUC6gSSagQJVsIRVuYEBVe6BAOwBAAAAAAAAAgAAElTDZ/pzc59jwIBnyJlFo4dFTkNPREVSRIeMTGF2ZjYzLjEuMTAyc3PVY8CLY8WIiQeUklk95R1nyKBFo4dFTkNPREVSRIeTTGF2YzYzLjEuMTAyIGxpYnZweGfIoUWjiERVUkFUSU9ORIeTMDA6MDA6MDEuMDAwMDAwMDAwAB9DtnWt54EAo6iBAACAsAIAnQEqQAAkAABHCIWFiJmEiAICAAaOT8zHm/FYAP7/q1CAHFO7a5G7j7OBALeK94EB8YIBsfCBAw==",
"base64",
)
await openSession(page, {
name: "ReviewVideo",
fileList: (path) => (path ? [] : [fileNode(directory, file)]),
seed: {
panes: { ses_reviewvideo: { review: true } },
},
})
await page.route(`**/api/fs/read/${file}*`, (route) =>
route.fulfill({
status: 200,
headers: { "access-control-allow-origin": "*", "content-type": "application/octet-stream" },
body: webm,
}),
)
const panel = page.locator("#review-panel")
await panel.getByRole("button", { name: "Open file" }).click()
await panel.getByRole("button", { name: file }).click()
await expect(panel.getByRole("tab", { name: file, exact: true })).toHaveAttribute("aria-selected", "true")
const stage = panel.locator('[data-slot="artifact-stage"]')
const video = stage.locator('video[data-slot="artifact-media"]')
const fullscreen = stage.getByRole("button", { name: "Enter full screen", exact: true })
const exitFullscreen = stage.getByRole("button", { name: "Exit full screen", exact: true })
await expect(video).toBeVisible()
await expect(fullscreen).toHaveAttribute("aria-pressed", "false")
const inlineBounds = (await stage.boundingBox())!
expect(inlineBounds.width).toBeLessThan(1000)
await video.evaluate((element) => {
element.dataset.e2eProbe = "retained"
})
await fullscreen.click()
await expect(exitFullscreen).toHaveAttribute("aria-pressed", "true")
await expect(stage).toHaveAttribute("data-expanded", "")
expect(await stage.evaluate((element) => element.matches(":popover-open"))).toBe(true)
expect(await page.evaluate(() => document.fullscreenElement)).toBeNull()
expect(await video.evaluate((element) => element.dataset.e2eProbe)).toBe("retained")
await expect.poll(() => stage.boundingBox()).toEqual({ x: 0, y: 0, width: 1440, height: 900 })
await page.keyboard.press("Escape")
await expect(fullscreen).toHaveAttribute("aria-pressed", "false")
await expect(stage).not.toHaveAttribute("data-expanded")
expect(await stage.evaluate((element) => element.matches(":popover-open"))).toBe(false)
expect(await video.evaluate((element) => element.dataset.e2eProbe)).toBe("retained")
await expect.poll(() => stage.boundingBox()).toEqual(inlineBounds)
await video.dblclick()
await expect(exitFullscreen).toHaveAttribute("aria-pressed", "true")
await page.mouse.click(8, 8)
await expect(fullscreen).toHaveAttribute("aria-pressed", "false")
expect(await video.evaluate((element) => element.dataset.e2eProbe)).toBe("retained")
})
test("restores review state and the side-panel tab per session", async ({ page }) => {
const sessions = [
{ id: "ses_review_state_a", title: "Alpha review state" },
@@ -33,6 +33,21 @@
-8px 0;
}
[data-slot="artifact-stage"][data-expanded] {
position: fixed;
inset: 0;
z-index: 50;
width: 100vw;
height: 100vh;
max-width: none;
max-height: none;
margin: 0;
padding: 0;
border: 0;
background-color: color-mix(in oklch, black 88%, transparent);
backdrop-filter: blur(8px);
}
[data-slot="artifact-media"] {
display: block;
border-radius: 4px;
@@ -41,6 +56,20 @@
0 12px 32px -12px color-mix(in oklch, var(--v2-text-text-base) 25%, transparent);
}
[data-slot="artifact-media"]::-webkit-media-controls-fullscreen-button {
visibility: hidden;
pointer-events: none;
}
[data-slot="artifact-video-fullscreen"] {
color: #ffffff;
}
[data-slot="artifact-video-fullscreen"]:hover > span,
[data-slot="artifact-video-fullscreen"]:focus-visible > span {
background-color: rgb(0 0 0 / 0.55);
}
[data-slot="artifact-stage"][data-zoom="fit"] [data-slot="artifact-media"] {
max-width: 100%;
max-height: 100%;
@@ -1,6 +1,7 @@
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"
import { createResizeObserver } from "@solid-primitives/resize-observer"
import { Button } from "@opencode/ui/button"
import { FileIcon } from "@opencode/ui/file-icon"
@@ -363,12 +364,110 @@ function ArtifactImage(props: MediaProps) {
}
function ArtifactVideo(props: MediaProps) {
const ctx = useExtension()
const url = createBlobUrl(() => props.content)
// Fullscreen belongs to one video: a new file starts fitted in the pane.
const [expandedUrl, setExpandedUrl] = createSignal<string>()
const [paused, setPaused] = createSignal(true)
const [active, setActive] = createSignal(false)
const [box, setBox] = createStore({ left: 0, top: 0, ready: false })
const expanded = () => expandedUrl() === url()
let stage: HTMLDivElement | undefined
let video: HTMLVideoElement | undefined
let idleTimer: ReturnType<typeof setTimeout> | undefined
const clearIdle = () => {
if (idleTimer !== undefined) clearTimeout(idleTimer)
idleTimer = undefined
}
const wake = () => {
setActive(true)
clearIdle()
idleTimer = setTimeout(() => setActive(false), 2500)
}
onCleanup(clearIdle)
const close = () => setExpandedUrl(undefined)
const toggle = () => setExpandedUrl(expanded() ? undefined : url())
const measure = () => {
if (!video || video.offsetWidth === 0 || video.offsetHeight === 0) return
// Chromium's media controls place the 48x48 fullscreen slot 48px from the right edge (beside the
// 48px overflow button) and 24px above the bottom edge (above the 24px timeline scrubber).
setBox({
left: video.offsetLeft + video.offsetWidth - 96,
top: video.offsetTop + video.offsetHeight - 72,
ready: true,
})
}
createResizeObserver(
() => [stage, video],
() => measure(),
)
// Top-layer promotion escapes the side panel's stacking context and <main>'s content containment
// while keeping the same <video> element mounted so playback never resets.
createKeyed(expanded, (open) => {
const el = stage
if (!el || !open) return
el.setAttribute("popover", "manual")
el.showPopover?.()
measure()
makeEventListener(
window,
"keydown",
(event: KeyboardEvent) => {
if (event.key !== "Escape") return
event.preventDefault()
event.stopPropagation()
close()
},
{ capture: true },
)
onCleanup(() => {
if (el.isConnected) el.hidePopover?.()
el.removeAttribute("popover")
measure()
})
})
const label = () => ctx.t(expanded() ? "view.exitFullscreen" : "view.fullscreen")
const controlsVisible = () => paused() || active()
return (
<div data-slot="artifact-stage" data-zoom="fit" class="relative min-h-0 flex-1 overflow-hidden">
<div class="absolute inset-0 flex items-center justify-center p-6">
<div
ref={stage}
data-slot="artifact-stage"
data-zoom="fit"
data-expanded={expanded() ? "" : undefined}
class="relative min-h-0 flex-1 overflow-hidden"
onPointerMove={wake}
onPointerLeave={() => {
clearIdle()
setActive(false)
}}
>
<div
classList={{
"absolute inset-0 flex items-center justify-center p-6": !expanded(),
"absolute inset-0 flex items-center justify-center px-8 pt-12 pb-8": expanded(),
}}
onClick={(event) => {
if (expanded() && event.target === event.currentTarget) close()
}}
>
<video
ref={video}
data-slot="artifact-media"
class="w-full bg-black"
controls
@@ -376,11 +475,57 @@ function ArtifactVideo(props: MediaProps) {
playsinline
onError={() => props.onError()}
src={url()}
onDblClick={toggle}
onPlay={() => setPaused(false)}
onPause={() => setPaused(true)}
onEnded={() => setPaused(true)}
onLoadedMetadata={(event) => {
const video = event.currentTarget
props.onInfo({ width: video.videoWidth, height: video.videoHeight, duration: video.duration })
const el = event.currentTarget
setPaused(el.paused)
props.onInfo({ width: el.videoWidth, height: el.videoHeight, duration: el.duration })
measure()
}}
/>
<button
type="button"
data-slot="artifact-video-fullscreen"
aria-label={label()}
aria-pressed={expanded()}
title={label()}
onClick={toggle}
style={box.ready ? { left: `${box.left}px`, top: `${box.top}px` } : { right: "72px", bottom: "48px" }}
classList={{
"absolute z-10 flex size-12 items-center justify-center transition-opacity focus-visible:opacity-100 focus-visible:outline-none":
true,
"opacity-100": controlsVisible(),
"pointer-events-none opacity-0": !controlsVisible(),
}}
>
<span class="flex size-9 items-center justify-center rounded-full transition-colors">
<Show
when={expanded()}
fallback={
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true">
<path
d="M3 6V3H6M10 3H13V6M13 10V13H10M6 13H3V10"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="square"
/>
</svg>
}
>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true">
<path
d="M3 5.5H5.5V3M13 5.5H10.5V3M10.5 13V10.5H13M5.5 13V10.5H3"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="square"
/>
</svg>
</Show>
</span>
</button>
</div>
</div>
)
@@ -9,6 +9,8 @@ export default {
"view.preview": "Preview",
"view.source": "Source",
"view.openInBrowser": "Open in browser",
"view.fullscreen": "Enter full screen",
"view.exitFullscreen": "Exit full screen",
"view.binary": "Binary file · {{size}}",
"view.table.rows.one": "{{count}} row",
"view.table.rows.other": "{{count}} rows",