diff --git a/packages/tui/src/config/index.tsx b/packages/tui/src/config/index.tsx index 92f595aae5b..43efe418270 100644 --- a/packages/tui/src/config/index.tsx +++ b/packages/tui/src/config/index.tsx @@ -120,6 +120,9 @@ export const Info = Schema.Struct({ }), tree: Schema.optional(Schema.Boolean).annotate({ description: "Show the diff file tree" }), single: Schema.optional(Schema.Boolean).annotate({ description: "Show only the selected file patch" }), + fullscreen: Schema.optional(Schema.Boolean).annotate({ + description: "Open the diff side panel full screen; remembers the last full screen toggle", + }), view: Schema.optional(Schema.Literals(["auto", "split", "unified"])).annotate({ description: "Diff layout; 'auto' selects a layout from the available width", }), @@ -159,7 +162,8 @@ export const Info = Schema.Struct({ description: "Group related transcript items automatically or render each item separately", }), verbosity: Schema.optional(Schema.Literals(["low", "medium", "high"])).annotate({ - description: "Transcript detail level: low summarizes each run of tools and thoughts, high opens exploration and instruction groups", + description: + "Transcript detail level: low summarizes each run of tools and thoughts, high opens exploration and instruction groups", }), image_preview: Schema.optional(Schema.Boolean).annotate({ description: "Show user attachment and tool-result images in the session transcript", @@ -285,8 +289,7 @@ export function resolve( input: Info, options: { terminalSuspend: boolean; environment?: Readonly> }, ): Resolved { - const tabsMode = - input.tabs?.mode ?? (input.tabs?.enabled === undefined ? "auto" : input.tabs.enabled ? "on" : "off") + const tabsMode = input.tabs?.mode ?? (input.tabs?.enabled === undefined ? "auto" : input.tabs.enabled ? "on" : "off") const keybinds: TuiKeybind.KeybindOverrides = { ...input.keybinds } if (!options.terminalSuspend) { keybinds["terminal.suspend"] = "none" diff --git a/packages/tui/src/context/panel.tsx b/packages/tui/src/context/panel.tsx index 8c4abe4b032..cea240a0c08 100644 --- a/packages/tui/src/context/panel.tsx +++ b/packages/tui/src/context/panel.tsx @@ -1,5 +1,6 @@ import type { PanelPresentation } from "@opencode/plugin/tui/context" import { batch, createContext, createMemo, createSignal, useContext, type ParentProps } from "solid-js" +import { SESSION_PANEL_SPLIT_MIN_WIDTH } from "../ui/layout" export type PanelTarget = { readonly plugin: string @@ -11,7 +12,7 @@ export function createPanelState() { const [current, setCurrent] = createSignal() const [requested, setRequested] = createSignal("panel") const [width, setWidth] = createSignal(0) - const canSplit = () => width() > 80 + const canSplit = () => width() >= SESSION_PANEL_SPLIT_MIN_WIDTH const presentation = createMemo(() => (canSplit() ? requested() : "fullscreen")) return { current, diff --git a/packages/tui/src/feature-plugins/system/diff-viewer.tsx b/packages/tui/src/feature-plugins/system/diff-viewer.tsx index f07c4719715..b2f1bcecf4e 100644 --- a/packages/tui/src/feature-plugins/system/diff-viewer.tsx +++ b/packages/tui/src/feature-plugins/system/diff-viewer.tsx @@ -20,6 +20,7 @@ import { DiffViewerImage, isDiffImageFile } from "./diff-viewer-image" import { DIALOG_INSET, DIALOG_LIST_INSET } from "../../ui/dialog" import { DialogSelect } from "../../ui/dialog-select" import { EmptyBorder } from "../../ui/border" +import { SESSION_PANEL_SPLIT_MIN_WIDTH } from "../../ui/layout" import { FilePath } from "../../ui/file-path" import { getScrollAcceleration } from "../../util/scroll" import { createDebouncedSignal } from "../../util/signal" @@ -44,6 +45,10 @@ const ROUTE = "diff" const MIN_SPLIT_WIDTH = 100 const FILE_TREE_MIN_WIDTH = 30 const FILE_TREE_MAX_WIDTH = 40 +const FULL_INSET = 2 +// The full layout keeps its file tree and inset cards only while its patches stay as wide as the narrowest docked +// panel, an equal split at the host's split threshold. Narrower full screens use the compact panel layout. +const FULL_LAYOUT_MIN_WIDTH = FILE_TREE_MIN_WIDTH + FULL_INSET * 2 + Math.floor(SESSION_PANEL_SPLIT_MIN_WIDTH / 2) const FILE_HEADER_HEIGHT = 2 const VCS_DIFF_CONTEXT_LINES = 12 type DiffMode = DiffSource @@ -296,7 +301,7 @@ function DiffBaseDialog(props: { ) } -type DiffPreferences = { tree?: boolean; single?: boolean; view?: "auto" | DiffView } +type DiffPreferences = { tree?: boolean; single?: boolean; view?: "auto" | DiffView; fullscreen?: boolean } export function DiffViewerContent(props: { context: Plugin.Context @@ -324,16 +329,18 @@ export function DiffViewerContent(props: { const currentSyntax = useThemes().currentSyntax const files = () => props.files const docked = () => props.panel?.presentation === "panel" + const width = () => props.panel?.width ?? dimensions().width + // Docked panels and narrow full screens share the compact layout: no file tree, flush cards, and a footer. + const compact = () => docked() || width() < FULL_LAYOUT_MIN_WIDTH + // Full screen has no pane beside it to focus, and is always the active input scope. + const focused = () => !docked() || props.panel?.focused === true // The side panel sits on the slot's raised surface; full screen keeps the base background. const surface = () => (docked() ? theme.background.raised.base : theme.background.base) // Cards are inset from the pane edges; the gaps between them run edge to edge. - const inset = () => (docked() ? 0 : 2) - const width = () => props.panel?.width ?? dimensions().width + const inset = () => (compact() ? 0 : FULL_INSET) const mode = () => props.mode const [fileTreeEnabled, setFileTreeEnabled] = createSignal(props.preferences?.tree ?? true) - const showFileTree = createMemo( - () => !docked() && width() >= 90 && showDiffViewerFileTree(fileTreeEnabled(), files().length), - ) + const showFileTree = createMemo(() => !compact() && showDiffViewerFileTree(fileTreeEnabled(), files().length)) const [singlePatch, setSinglePatch] = createSignal(props.preferences?.single ?? false) const fileTreeWidth = createMemo(() => Math.max(FILE_TREE_MIN_WIDTH, Math.min(FILE_TREE_MAX_WIDTH, Math.floor(width() / 4))), @@ -685,9 +692,9 @@ export function DiffViewerContent(props: { id: "diff.toggle_file_tree", title: "Toggle diff viewer file tree", group: "VCS", - enabled: () => !docked(), + enabled: () => !compact(), run() { - if (docked()) return + if (compact()) return const next = !fileTreeEnabled() setFileTreeEnabled(next) props.onPreferencesChange?.({ tree: next }) @@ -740,7 +747,15 @@ export function DiffViewerContent(props: { title: "Toggle diff viewer full screen", group: "VCS", enabled: () => props.panel !== undefined, - run: () => props.panel?.toggleFullscreen(), + run: () => { + const panel = props.panel + if (!panel) return + const before = panel.presentation + panel.toggleFullscreen() + // A narrow terminal forces full screen and ignores the toggle; only a real toggle is remembered. + if (panel.presentation === before) return + props.onPreferencesChange?.({ fullscreen: panel.presentation === "fullscreen" }) + }, }, { id: "diff.help", @@ -799,7 +814,7 @@ export function DiffViewerContent(props: { context={props.context} single={singlePatch()} fullscreen={props.panel !== undefined} - tree={!docked()} + tree={!compact()} /> )) dialog.set({ size: "medium", centered: true }) @@ -840,8 +855,9 @@ export function DiffViewerContent(props: { - + Loading diff… - + {!props.sourceBase && needsBase(mode()) ? "Could not load diff. Choose a base branch from Diff source, or select Uncommitted." @@ -896,14 +912,14 @@ export function DiffViewerContent(props: { - + Committed comparison unavailable without base metadata. Choose a base branch from Diff source. - + No changes to show @@ -1002,7 +1018,7 @@ export function DiffViewerContent(props: { height={FILE_HEADER_HEIGHT} zIndex={1} backgroundColor={background()} - paddingLeft={docked() ? 2 : 1} + paddingLeft={compact() ? 2 : 1} paddingRight={1} paddingBottom={1} > @@ -1036,7 +1052,13 @@ export function DiffViewerContent(props: { + {mode() === "committed" && image() ? "Committed image preview unavailable. The working-tree image is not shown." @@ -1071,7 +1093,7 @@ export function DiffViewerContent(props: { filetype={filetype(entry.file.file)} syntaxStyle={currentSyntax()} showLineNumbers={true} - gutterPadding={docked() ? 1 : 0} + gutterPadding={compact() ? 1 : 0} width="100%" wrapMode="char" fg={theme.text.base} @@ -1100,21 +1122,23 @@ export function DiffViewerContent(props: { - - {/* The footer sits on the terminal background, eased in by a half-cell like the prompt. */} + + {/* Docked, the footer sits on the terminal background, eased in by a half-cell like the prompt. */} - - + + + + { if (event.button !== MouseButton.LEFT) return + if (!docked()) return close() if (!props.panel?.focused) props.panel?.focus() }} > - {props.context.keymap.shortcuts("pane.focus.left")[0] ?? ""} - focus prompt + {/* Without a prompt beside the viewer, closing is the way back to the session. */} + {props.context.keymap.shortcuts(docked() ? "pane.focus.left" : "diff.close")[0] ?? ""} + {docked() ? " focus prompt" : " close"} - + - + + + - + @@ -1171,9 +1199,10 @@ function CardGap(props: { glyph: "▄" | "▀"; card: RGBA; surface: RGBA; inset ) return ( - {half(props.surface, props.inset)} + {/* A zero-width inset still claims a cell, which would notch flush cards. */} + 0}>{half(props.surface, props.inset)} {half(props.card)} - {half(props.surface, props.inset)} + 0}>{half(props.surface, props.inset)} ) } @@ -1296,7 +1325,13 @@ function Commands(props: { context: Plugin.Context }) { props.context.ui.panel.close() return } - if (config.data.experimental?.["diff-panel"] === true && props.context.ui.panel.open(ROUTE)) return + if ( + config.data.experimental?.["diff-panel"] === true && + props.context.ui.panel.open(ROUTE, { + presentation: config.data.diffs?.fullscreen === true ? "fullscreen" : "panel", + }) + ) + return const returnRoute: Route = route.type === "home" ? { type: "home" } diff --git a/packages/tui/src/ui/layout.ts b/packages/tui/src/ui/layout.ts index d48e613697b..803ae768971 100644 --- a/packages/tui/src/ui/layout.ts +++ b/packages/tui/src/ui/layout.ts @@ -4,6 +4,9 @@ export const SESSION_TABS_COMPACT_BREAKPOINT = 12 export const SESSION_SIDEBAR_MAX_WIDTH = 72 const SESSION_CONTENT_MIN_WIDTH = 44 const SESSION_CONTENT_PREFERRED_WIDTH = 64 +// Like vertical tabs, a docked panel fits when the session keeps its preferred width beside a minimum-width pane. +// Narrower, panels take over the screen. +export const SESSION_PANEL_SPLIT_MIN_WIDTH = SESSION_CONTENT_PREFERRED_WIDTH + SESSION_CONTENT_MIN_WIDTH export function sessionTabsFitVertically(total: number, width = SESSION_SIDEBAR_WIDTH) { return total >= width + SESSION_CONTENT_PREFERRED_WIDTH diff --git a/packages/tui/test/cli/tui/diff-viewer.test.tsx b/packages/tui/test/cli/tui/diff-viewer.test.tsx index aeb203bf10a..3203d36abdc 100644 --- a/packages/tui/test/cli/tui/diff-viewer.test.tsx +++ b/packages/tui/test/cli/tui/diff-viewer.test.tsx @@ -322,6 +322,7 @@ test.each([50, 80, 160])( const header = viewer.app.renderer.root.findDescendantById("diff-source-header")! const source = viewer.app.renderer.root.findDescendantById("diff-source-switch")! const count = viewer.app.renderer.root.findDescendantById("diff-review-count")! + // Full screen keeps the header on its top row, compact or not. expect(header.height).toBe(1) expect(source.y).toBe(header.y) expect(count.y).toBe(header.y) @@ -370,18 +371,21 @@ test.each([50, 80, 100, 160])( try { const header = viewer.app.renderer.root.findDescendantById("diff-source-header")! const count = viewer.app.renderer.root.findDescendantById("diff-review-count")! - const row = viewer.app.captureCharFrame().split("\n")[header.y] + const y = header.y + header.height - 1 + const row = viewer.app.captureCharFrame().split("\n")[y] expect(header.height).toBe(1) expect(row).toContain("Committed · vs") expect(row).toContain("0/1") expect(row).not.toContain("release/very-long-comparison-branch-name-that-does-not-fit-in-the-header") - expect(count.y).toBe(header.y) + expect(count.y).toBe(y) expect(count.x + count.width).toBeLessThanOrEqual(header.x + header.width) const hint = viewer.app.renderer.root.findDescendantById("diff-help-shortcut")! - if (width < 90) { - expect(hint.y).toBe(header.y) - expect(hint.x).toBeGreaterThan(count.x + count.width) - expect(findScrollBox(viewer.app.renderer.root)!.viewport.y).toBeGreaterThan(header.y) + const scroll = findScrollBox(viewer.app.renderer.root)! + if (width < 88) { + // The compact layout moves help from the header row into its footer. + expect(hint.y).toBe(viewer.app.renderer.root.findDescendantById("diff-footer")!.y) + expect(hint.y).toBeGreaterThanOrEqual(scroll.viewport.y + scroll.viewport.height) + expect(scroll.viewport.y).toBeGreaterThan(y) } } finally { viewer.app.renderer.destroy() @@ -1037,6 +1041,7 @@ test.each([100, 160])("shared pane edges align headings and stay fixed at %i col await viewer.app.flush() expect(viewer.app.renderer.root.findDescendantById("diff-tree-top-edge")).toBeUndefined() expect(viewer.app.renderer.root.findDescendantById("diff-patch-top-edge")).toBeDefined() + // The compact full screen header is one row, directly above the shared pane edge. expect(viewer.app.captureCharFrame().split("\n")[title + 1]).toContain("file01.txt") } finally { viewer.app.renderer.destroy() @@ -1175,13 +1180,18 @@ test("compact gutter help leaves the full patch viewport available when the side viewer.app.mockInput.pressKey("b") await viewer.app.flush() expect(viewer.app.renderer.root.findDescendantById("diff-help-shortcut")!.y).toBe(21) + // Too narrow for the tree, full screen switches to the compact layout and its footer holds the help. viewer.app.resize(80, 24) await viewer.app.flush() - expect(viewer.app.renderer.root.findDescendantById("diff-help-shortcut")!.y).toBe(0) - expect(viewer.app.renderer.root.findDescendantById("diff-help-shortcut")!.x).toBe(79) - expect(scroll.viewport.y + scroll.viewport.height).toBe(24) + const footer = viewer.app.renderer.root.findDescendantById("diff-footer")! + expect(viewer.app.renderer.root.findDescendantById("diff-files")).toBeUndefined() + expect(viewer.app.renderer.root.findDescendantById("diff-help-shortcut")!.y).toBe(footer.y) + expect(scroll.viewport.y + scroll.viewport.height).toBe(footer.y) expect(viewer.app.captureCharFrame()).not.toContain("? help") - expect(viewer.app.captureCharFrame().split("\n")[0].at(-1)).toBe("?") + // No padding: the header and footer sit on the first and last rows. + expect(viewer.app.captureCharFrame().split("\n")[0]).toContain("All") + expect(footer.y).toBe(23) + expect(viewer.app.captureCharFrame().split("\n")[footer.y]).toMatch(/^ escape close\s+\? see all $/) viewer.app.mockInput.pressKey("d") await viewer.app.waitForFrame((frame) => frame.includes("Diff source")) viewer.app.mockInput.pressEscape() @@ -1191,6 +1201,49 @@ test("compact gutter help leaves the full patch viewport available when the side } }) +test("full screen keeps its tree down to 88 columns and uses the compact layout below", async () => { + const viewer = await renderDiffViewer(manyDiffs.slice(0, 3), { width: 88, height: 24, kittyKeyboard: true }) + try { + await viewer.app.waitForFrame((frame) => frame.includes("const first")) + viewer.app.mockInput.pressKey("m") + await viewer.app.flush() + const scroll = findScrollBox(viewer.app.renderer.root)! + expect(viewer.app.renderer.root.findDescendantById("diff-files")).toBeDefined() + expect(viewer.app.renderer.root.findDescendantById("diff-footer")).toBeUndefined() + // Full cards are inset two columns from the patch pane. + expect(viewer.app.renderer.root.findDescendantById("diff-file-header-0")!.width).toBe(scroll.viewport.width - 4) + + viewer.app.resize(87, 24) + await viewer.app.flush() + expect(findScrollBox(viewer.app.renderer.root)).toBe(scroll) + expect(viewer.app.renderer.root.findDescendantById("diff-files")).toBeUndefined() + expect(viewer.app.renderer.root.findDescendantById("diff-file-header-0")!.width).toBe(87) + const second = viewer.app.renderer.root.findDescendantById("diff-file-header-1") + if (!(second instanceof BoxRenderable)) throw new Error("Missing second file title") + // The gap above a flush card takes the card's color across the full width, without an inset notch. + expect( + viewer.app + .captureSpans() + .lines[second.y - 1].spans.flatMap((span) => Array.from({ length: span.width }, () => span.fg)), + ).toEqual(Array.from({ length: 87 }, () => second.backgroundColor)) + expect(viewer.app.renderer.root.findDescendantById("diff-review-count")!.y).toBe(0) + const footer = viewer.app.renderer.root.findDescendantById("diff-footer")! + expect(viewer.app.captureCharFrame().split("\n")[footer.y]).toMatch(/^ escape close\s+\? see all $/) + expect(viewer.app.captureCharFrame()).toContain("1/3") + viewer.app.mockInput.pressKey("b") + await viewer.app.flush() + expect(viewer.app.renderer.root.findDescendantById("diff-files")).toBeUndefined() + + viewer.app.resize(88, 24) + await viewer.app.flush() + expect(viewer.app.renderer.root.findDescendantById("diff-files")).toBeDefined() + expect(viewer.app.renderer.root.findDescendantById("diff-footer")).toBeUndefined() + expect(viewer.app.captureCharFrame()).toContain("1/3") + } finally { + viewer.app.renderer.destroy() + } +}) + test("compact help scrolls at a narrow size and reflects customized bindings", async () => { const viewer = await renderDiffViewer(hunkDiff, { width: 50, @@ -1209,7 +1262,8 @@ test("compact help scrolls at a narrow size and reflects customized bindings", a expect(viewer.app.captureCharFrame()).not.toContain("alt+↓") scroll.scrollTo(scroll.scrollHeight) await viewer.app.flush() - expect(viewer.app.captureCharFrame()).toContain("Show / hide file tree") + // The compact layout has no file tree to toggle. + expect(viewer.app.captureCharFrame()).not.toContain("Show / hide file tree") expect(viewer.app.captureCharFrame()).not.toContain("Focus files") expect(viewer.app.captureCharFrame()).toMatch(/x\s+Close diff viewer/) viewer.app.mockInput.pressEscape() @@ -1359,7 +1413,8 @@ test.each(["patch", "image", "fallback"] as const)( if (!(header instanceof BoxRenderable)) throw new Error("Missing reviewed file title") expect(header.parent?.height).toBe(header.height) expect(header.height).toBe(2) - expect(viewer.app.captureCharFrame().split("\n")[header.y + 1].trim()).toBe("▀".repeat(header.width + 4)) + // Compact cards are flush with the pane edges. + expect(viewer.app.captureCharFrame().split("\n")[header.y + 1].trim()).toBe("▀".repeat(header.width)) expect(header.y).toBe(scroll.viewport.y) expect(viewer.app.captureCharFrame()).toContain(file.file) expect(viewer.app.captureCharFrame()).toContain("✓") diff --git a/packages/tui/test/fixture/app.ts b/packages/tui/test/fixture/app.ts index b76d2db1e7a..9be3ac94e35 100644 --- a/packages/tui/test/fixture/app.ts +++ b/packages/tui/test/fixture/app.ts @@ -29,12 +29,22 @@ export async function createAppFixture( const ready = Promise.withResolvers() const events = createEventStream() const calls = createFetch(input.fetch, events) + // Updates apply to a copy, as a config file would, so preference writes persist for the rest of the test. + let config: Config.Info = structuredClone(input.config ?? { animations: false }) const server = Bun.serve({ port: 0, fetch: (request) => calls.fetch(request) }) const task = Effect.runPromise( run({ app: { name: "test", version: "test", channel: "test" }, server: { endpoint: { url: server.url.toString() } }, - config: { get: async () => input.config ?? { animations: false }, update: async () => ({}) }, + config: { + get: async () => config, + update: async (mutate) => { + const next = structuredClone(config) + mutate(next) + config = next + return next + }, + }, packages: { prepare: async () => ({ directory: "" }) }, terminalHandoff: async () => ({ renderer: setup.renderer, mode: "dark", complete: ready.resolve }), args: input.args ?? {}, @@ -59,6 +69,7 @@ export async function createAppFixture( return { ...setup, events, + config: () => config, ready: ready.promise, async [Symbol.asyncDispose]() { try { diff --git a/packages/tui/test/panel.test.ts b/packages/tui/test/panel.test.ts index 7d610241026..4aaf51f28d9 100644 --- a/packages/tui/test/panel.test.ts +++ b/packages/tui/test/panel.test.ts @@ -1,6 +1,7 @@ import { expect, test } from "bun:test" import { createRoot } from "solid-js" import { createPanelState } from "../src/context/panel" +import { SESSION_PANEL_SPLIT_MIN_WIDTH } from "../src/ui/layout" test("presentation changes preserve the selected panel identity", () => { createRoot((dispose) => { @@ -25,11 +26,11 @@ test("narrow geometry overrides presentation without discarding the user's choic createRoot((dispose) => { const panels = createPanelState() panels.open({ plugin: "review", name: "diff", sessionID: "session" }) - panels.setWidth(80) + panels.setWidth(SESSION_PANEL_SPLIT_MIN_WIDTH - 1) expect(panels.canSplit()).toBe(false) expect(panels.presentation()).toBe("fullscreen") panels.toggleFullscreen() - panels.setWidth(81) + panels.setWidth(SESSION_PANEL_SPLIT_MIN_WIDTH) expect(panels.canSplit()).toBe(true) expect(panels.presentation()).toBe("panel") panels.toggleFullscreen() diff --git a/packages/tui/test/session-panel.test.tsx b/packages/tui/test/session-panel.test.tsx index ef80b98d6f3..34dcff5efdc 100644 --- a/packages/tui/test/session-panel.test.tsx +++ b/packages/tui/test/session-panel.test.tsx @@ -138,6 +138,42 @@ test("repeated fullscreen toggles retain the viewer, transcript, scroll, and rev expect(setup.requests.diff[0].searchParams.get("base")).toBe("refs/heads/v2") }) +test("the diff panel reopens in the presentation last chosen with the fullscreen toggle", async () => { + await using state = await tmpdir() + await using setup = await createSessionFixture(state.path) + await ready(setup) + const reopen = async () => { + setup.mockInput.pressKey("F6") + await setup.waitFor(() => setup.renderer.root.findDescendantById("session-panel") === undefined) + setup.mockInput.pressKey("F6") + await panelReady(setup) + } + setup.mockInput.pressKey("F6") + await panelReady(setup) + expect(node(setup, "session-panel").width).toBeLessThan(setup.renderer.width) + + setup.mockInput.pressKey("f") + await setup.waitFor(() => node(setup, "session-panel").width === setup.renderer.width) + expect(setup.config().diffs?.fullscreen).toBe(true) + await reopen() + expect(node(setup, "session-panel").width).toBe(setup.renderer.width) + + setup.mockInput.pressKey("f") + await setup.waitFor(() => node(setup, "session-panel").width < setup.renderer.width) + expect(setup.config().diffs?.fullscreen).toBe(false) + await reopen() + expect(node(setup, "session-panel").width).toBeLessThan(setup.renderer.width) + + // A terminal too narrow to split forces full screen; the ignored toggle leaves the preference alone. + setup.resize(100, 36) + await setup.waitFor(() => node(setup, "session-panel").width === 100) + setup.mockInput.pressKey("f") + await setup.flush() + expect(setup.config().diffs?.fullscreen).toBe(false) + setup.resize(160, 36) + await setup.waitFor(() => node(setup, "session-panel").width < setup.renderer.width) +}) + test("docked tree commands leave the full-screen tree preference unchanged", async () => { await using state = await tmpdir() await using setup = await createSessionFixture(state.path, { diffs: { tree: true } }) @@ -222,6 +258,69 @@ test.each([60, 80])("a panel opened at %i columns can split after growing withou expect(setup.requests.diff).toHaveLength(1) }) +test("narrow terminals show the panel full screen, then compact, and dock again without remounting", async () => { + await using state = await tmpdir() + await using setup = await createSessionFixture(state.path, { diffs: { tree: true } }) + await ready(setup) + const prompt = editor(setup) + const transcript = node(setup, "msg_panel_11") + setup.mockInput.pressKey("F6") + await panelReady(setup) + const panel = node(setup, "session-panel") + const patches = scroll(setup) + setup.mockInput.pressKey("m") + await setup.waitForFrame(() => text(setup, "diff-review-count") === "1/4") + setup.mockInput.pressKey("j") + await setup.waitFor(() => patches.scrollTop > 0) + const top = patches.scrollTop + const retained = () => { + expect(node(setup, "session-panel")).toBe(panel) + expect(scroll(setup)).toBe(patches) + expect(node(setup, "msg_panel_11")).toBe(transcript) + expect(prompt.isDestroyed).toBe(false) + expect(setup.renderer.currentFocusedRenderable).toBe(panel) + expect(setup.requests.diff).toHaveLength(1) + } + + // Below the split threshold the panel takes over with the full layout, including its file tree. + setup.resize(107, 36) + await setup.waitFor(() => panel.width === 107) + retained() + expect(patches.scrollTop).toBe(top) + expect(setup.renderer.root.findDescendantById("diff-files")).toBeDefined() + expect(setup.renderer.root.findDescendantById("diff-footer")).toBeUndefined() + expect(text(setup, "diff-source-header")).toContain("1/4") + setup.mockInput.pressKey("j") + await setup.waitFor(() => patches.scrollTop > top) + expect(prompt.plainText).toBe("") + + // Narrower still, the full screen keeps the compact panel rendering without a prompt to focus. + setup.resize(80, 36) + await setup.waitFor(() => panel.width === 80 && setup.renderer.root.findDescendantById("diff-footer") !== undefined) + retained() + expect(setup.renderer.root.findDescendantById("diff-files")).toBeUndefined() + expect(text(setup, "diff-review-count")).toBe("1/4") + expect(text(setup, "diff-footer")).toMatch(/^escape close\s+\? see all$/) + expect(text(setup, "diff-footer")).not.toContain("focus prompt") + focus(setup, "left") + await setup.flush() + expect(setup.renderer.currentFocusedRenderable).toBe(panel) + + setup.resize(108, 36) + await setup.waitFor(() => panel.width < 108 && panel.x > 0) + retained() + expect(setup.renderer.root.findDescendantById("diff-files")).toBeUndefined() + expect(text(setup, "diff-footer")).toContain("ctrl+x ← focus prompt") + focus(setup, "left") + await setup.waitFor(() => setup.renderer.currentFocusedEditor === prompt) + const docked = patches.scrollTop + await setup.mockInput.typeText("jq") + await setup.flush() + expect(prompt.plainText).toBe("jq") + expect(patches.scrollTop).toBe(docked) + expect(node(setup, "session-panel")).toBe(panel) +}) + test("split eligibility uses the columns remaining beside vertical session tabs", async () => { await using state = await tmpdir() await using setup = await createSessionFixture(state.path, {