Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/tui/src/component/dialog-experiments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ type Experiment = {
// In-flight features anyone can opt into. Each entry is temporary: an
// experiment either graduates (delete the entry, make the behavior
// unconditional) or dies (delete the entry and the branch it gated).
export const experiments: Experiment[] = []
export const experiments: Experiment[] = [
{
id: "diff-panel",
title: "Diff side panel",
description: "Open /diff in a panel beside the session instead of full screen",
},
]

export function DialogExperiments() {
const config = useConfig()
Expand Down
11 changes: 6 additions & 5 deletions packages/tui/src/feature-plugins/system/diff-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -840,9 +840,9 @@ export function DiffViewerContent(props: {
id="diff-source-header"
paddingLeft={2}
paddingRight={2}
paddingTop={1}
paddingBottom={1}
height={3}
paddingTop={docked() ? 1 : 0}
paddingBottom={docked() ? 1 : 0}
height={docked() ? 3 : 1}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opencode bot explain these changes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hunk undoes a layout change from #47152 for the full-screen diff only. The docked side panel keeps the new layout.

  • What feat(tui): render diffs in plugin panel slots #47152 did (c0d41d2b2): it changed #diff-source-header from height={1} with no vertical padding to paddingTop={1} paddingBottom={1} height={3}. That gives the header breathing room inside the docked panel. But the header renders whenever the file tree is hidden (<Show when={!showFileTree()}>, line 838), and that also covers the narrow full-screen diff (width < 90 or tree turned off; see line 334). So the full-screen view also got a 3-row header, which pushed the diff down two rows.
  • What this PR does (lines 843–845): it applies the padding and the 3-row height only when docked(), i.e. props.panel?.presentation === "panel" (line 325). Otherwise the header is back to a single row with no padding, exactly as before feat(tui): render diffs in plugin panel slots #47152.
  • The matching ? hint change (line 1137): feat(tui): render diffs in plugin panel slots #47152 moved the absolutely positioned compact HelpShortcut from top={0} to top={1} so it lined up with the padded header. Now that the full-screen header is one row again, it goes back to top={0}. This block already has !docked() in its condition, so the panel isn't affected; the panel has its own footer (line 1101).

Together these make the full-screen diff look the same as before #47152, which is what the experiment needs when it's off. The rest of the PR is the /diff command change (line ~1297): it only calls ui.panel.open(ROUTE) when experimental["diff-panel"] === true, and otherwise falls through to the full-screen route.

To check this, I compared the PR diff against c0d41d2b2 and its parent, and the old values match. I didn't run the tests or render anything. I made no changes to the checkout.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but in the other PR, the docked mode is optional, you can also switch it to fullscreen mode. so it was buggy before in fullscreen mode?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not buggy, just a different look. When you switch the panel to fullscreen, docked() is false, so it takes the same non-docked layout path as the standalone full-screen diff. #47152 padded the header for every view, so both of those views got the 3-row header with the ? hint at top={1}. That was consistent and didn't break anything, but it changed the full-screen layout from what it was before #47152.

How it fits together:

  • docked() is just props.panel?.presentation === "panel" (diff-viewer.tsx:325). presentation turns into "fullscreen" when you toggle it (diff.toggle_fullscreen), or automatically when width <= 80 (context/panel.tsx:14-15).
  • The header only renders when there's no file tree (line 838). Non-docked views show the tree at width >= 90 when it's enabled (line 334). So the extra padding only showed up in non-docked views narrower than 90 columns or with the tree turned off, in both panel-fullscreen and standalone.
  • With this PR, panel-fullscreen also goes back to the 1-row header with ? at top={0}. It matches the standalone full-screen diff again. Only the side-by-side docked panel keeps the padded 3-row header. That looks intentional, and I think it's right: fullscreen looks the same however you got there.

I checked this by reading the code. I didn't render panel-fullscreen mode, and the PR's Drive runs don't mention panel→fullscreen at a narrow width either. The 80-column runs would hit the forced-fullscreen path, though. No changes made.

flexShrink={0}
flexDirection="row"
gap={1}
Expand Down Expand Up @@ -1134,7 +1134,7 @@ export function DiffViewerContent(props: {
</box>
</Show>
<Show when={!showFileTree() && !docked()}>
<box position="absolute" top={1} right={0} width={1} height={1}>
<box position="absolute" top={0} right={0} width={1} height={1}>
<HelpShortcut compact />
</box>
</Show>
Expand Down Expand Up @@ -1276,6 +1276,7 @@ function DiffViewerHelpDialog(props: { context: Plugin.Context; single: boolean;
}

function Commands(props: { context: Plugin.Context }) {
const config = useConfig()
props.context.keymap.layer(() => ({
mode: "global",
commands: [
Expand All @@ -1293,7 +1294,7 @@ function Commands(props: { context: Plugin.Context }) {
props.context.ui.panel.close()
return
}
if (props.context.ui.panel.open(ROUTE)) return
if (config.data.experimental?.["diff-panel"] === true && props.context.ui.panel.open(ROUTE)) return
const returnRoute: Route =
route.type === "home"
? { type: "home" }
Expand Down
35 changes: 15 additions & 20 deletions packages/tui/test/cli/tui/diff-viewer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,10 @@ 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")!
// Without the file tree, the header has one row of padding above and below its title.
const padded = width < 100
expect(header.height).toBe(padded ? 3 : 1)
const title = header.y + (padded ? 1 : 0)
expect(source.y).toBe(title)
expect(count.y).toBe(title)
expect(viewer.app.captureCharFrame().split("\n")[title]).toMatch(/All · vs release\s+0\/1/)
expect(header.height).toBe(1)
expect(source.y).toBe(header.y)
expect(count.y).toBe(header.y)
expect(viewer.app.captureCharFrame().split("\n")[header.y]).toMatch(/All · vs release\s+0\/1/)
expect(viewer.app.captureCharFrame()).not.toContain("reviewed")
expect(viewer.vcsDiffInput()).toMatchObject({ base: "refs/remotes/origin/release" })
await viewer.app.mockMouse.click(source.x, source.y)
Expand All @@ -348,7 +345,7 @@ test.each([50, 80, 160])(
await viewer.app.waitForFrame((frame) => !frame.includes("Diff source"))
viewer.commands.get("diff.mark_reviewed")!.run()
await viewer.app.flush()
expect(viewer.app.captureCharFrame().split("\n")[title]).toMatch(/All · vs release\s+1\/1/)
expect(viewer.app.captureCharFrame().split("\n")[header.y]).toMatch(/All · vs release\s+1\/1/)
await chooseSource(viewer, 2)
await viewer.app.waitForFrame((frame) => frame.includes("Uncommitted · vs HEAD"))
viewer.app.mockInput.pressKey("d")
Expand All @@ -373,20 +370,18 @@ 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 padded = width < 100
const title = header.y + (padded ? 1 : 0)
const row = viewer.app.captureCharFrame().split("\n")[title]
expect(header.height).toBe(padded ? 3 : 1)
const row = viewer.app.captureCharFrame().split("\n")[header.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(title)
expect(count.y).toBe(header.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(title)
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 + header.height - 1)
expect(findScrollBox(viewer.app.renderer.root)!.viewport.y).toBeGreaterThan(header.y)
}
} finally {
viewer.app.renderer.destroy()
Expand Down Expand Up @@ -1042,7 +1037,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()
expect(viewer.app.captureCharFrame().split("\n")[title + 3]).toContain("file01.txt")
expect(viewer.app.captureCharFrame().split("\n")[title + 1]).toContain("file01.txt")
} finally {
viewer.app.renderer.destroy()
}
Expand Down Expand Up @@ -1167,9 +1162,9 @@ test("compact gutter help leaves the full patch viewport available when the side
await viewer.app.flush()
const scroll = findScrollBox(viewer.app.renderer.root)!
const hint = viewer.app.renderer.root.findDescendantById("diff-help-shortcut")!
expect(hint.y).toBe(1)
expect(hint.y).toBe(0)
expect(hint.x).toBe(159)
expect(scroll.viewport.y).toBe(4)
expect(scroll.viewport.y).toBe(2)
expect(scroll.viewport.y + scroll.viewport.height).toBe(24)
await viewer.app.mockMouse.click(hint.x, hint.y)
await viewer.app.waitForFrame((frame) => frame.includes("Diff shortcuts"))
Expand All @@ -1182,11 +1177,11 @@ test("compact gutter help leaves the full patch viewport available when the side
expect(viewer.app.renderer.root.findDescendantById("diff-help-shortcut")!.y).toBe(21)
viewer.app.resize(80, 24)
await viewer.app.flush()
expect(viewer.app.renderer.root.findDescendantById("diff-help-shortcut")!.y).toBe(1)
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)
expect(viewer.app.captureCharFrame()).not.toContain("? help")
expect(viewer.app.captureCharFrame().split("\n")[1].at(-1)).toBe("?")
expect(viewer.app.captureCharFrame().split("\n")[0].at(-1)).toBe("?")
viewer.app.mockInput.pressKey("d")
await viewer.app.waitForFrame((frame) => frame.includes("Diff source"))
viewer.app.mockInput.pressEscape()
Expand Down
18 changes: 18 additions & 0 deletions packages/tui/test/session-panel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ import { createAppFixture } from "./fixture/app"
import { directory, json } from "./fixture/tui-client"
import { tmpdir } from "./fixture/fixture"

test("/diff opens the full-screen diff when the side panel experiment is off", async () => {
await using state = await tmpdir()
await using setup = await createSessionFixture(state.path, { panel: false })
await ready(setup)
await setup.mockInput.typeText("/diff")
await setup.waitForFrame((frame) => frame.includes("Open diff viewer"))
setup.mockInput.pressEnter()
await setup.waitForFrame((frame) => frame.includes("file00.txt"), { maxPasses: 120 })
expect(setup.renderer.root.findDescendantById("session-panel")).toBeUndefined()
expect(setup.renderer.root.findDescendantById("diff-footer")).toBeUndefined()
expect(setup.captureCharFrame()).not.toContain("Transcript item 11")
setup.mockInput.pressKey("q")
await setup.waitForFrame((frame) => frame.includes("Transcript item 11") && !frame.includes("file00.txt"))
expect(setup.renderer.root.findDescendantById("session-panel")).toBeUndefined()
})

test("/diff focuses the production session panel without sending typing to the prompt", async () => {
await using state = await tmpdir()
await using setup = await createSessionFixture(state.path)
Expand Down Expand Up @@ -458,6 +474,7 @@ async function createSessionFixture(
keybinds?: Config.Info["keybinds"]
permission?: boolean
form?: boolean
panel?: boolean
} = {},
) {
// Drafts survive app disposal in memory, so each production app needs its own session identity.
Expand Down Expand Up @@ -512,6 +529,7 @@ async function createSessionFixture(
session: { sidebar: "hide" },
// Keep patch geometry stable while testing host presentation changes, not split/unified diff layout.
diffs: { tree: false, view: "unified", ...input.diffs },
experimental: { "diff-panel": input.panel ?? true },
keybinds: { "diff.open": "f6", ...input.keybinds },
},
fetch: async (url, request) => {
Expand Down
Loading