From 31b265cb4166e13d2f7bfdb168f42a7d04db02e2 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Mon, 23 Nov 2026 15:17:34 +0800 Subject: [PATCH] fix(vcs): align the New Worktree dialog (#5367) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Align the repository, checkout, branch, name, location and setup fields in one label-and-control grid. Use the standard dialog type size for labels and keep the worktree path preview beneath the Location field. - Let the `.worktreeinclude` edit action wrap below its checkbox in narrow windows. With setup expanded, the standard dialog is about 118 logical pixels shorter, and the setup field fits without scrolling in a 440 × 520 window. --- e2e/newWorktreeLayout.spec.ts | 83 +++++++++ src/features/vcs/NewWorktreeDialog.tsx | 241 +++++++++++++------------ src/features/vcs/common.module.css | 33 ++++ 3 files changed, 244 insertions(+), 113 deletions(-) create mode 100644 e2e/newWorktreeLayout.spec.ts diff --git a/e2e/newWorktreeLayout.spec.ts b/e2e/newWorktreeLayout.spec.ts new file mode 100644 index 000000000..dde35aae0 --- /dev/null +++ b/e2e/newWorktreeLayout.spec.ts @@ -0,0 +1,83 @@ +import { expect, ipcCalls, stubDesktop, test } from "./fixtures"; + +test("New Worktree keeps form fields aligned and creates the selected worktree in a short window", async ({ + workbench: page, +}) => { + await page.setViewportSize({ width: 1120, height: 740 }); + await stubDesktop(page); + await page.evaluate(async () => { + const root = "/dev/acme-api"; + const service = `${root}/service`; + window.__ipc.handlers.vcs_branches = () => [{ name: "main", current: true, remote: false }]; + window.__ipc.handlers.vcs_tags = () => []; + window.__ipc.handlers.vcs_worktrees = ({ repo }) => [{ path: repo, branch: "main", main: true, submodule: false }]; + window.__ipc.handlers.vcs_worktree_include = () => ({ exists: true }); + window.__ipc.handlers.vcs_add_worktree = () => ({ copyWarning: null, setupWarning: null }); + const store = "/src/features/vcs/store.ts"; + const { useVcs } = await import(/* @vite-ignore */ store); + useVcs.setState({ root, roots: [root, service], repo: root, available: true }); + const context = "/src/platform/context.ts"; + const { setContext } = await import(/* @vite-ignore */ context); + setContext("vcsAvailable", true); + const actions = "/src/platform/actions.ts"; + const { executeAction } = await import(/* @vite-ignore */ actions); + await executeAction("vcs.newWorktree"); + }); + + const dialog = page.getByRole("dialog", { name: "New Worktree" }); + const name = dialog.getByRole("textbox", { name: "Name:" }); + const branch = dialog.getByRole("textbox", { name: "New branch name" }); + const location = dialog.getByRole("textbox", { name: "Location:" }); + const repository = dialog.getByRole("button", { name: "Repository", exact: true }); + const checkout = dialog.getByRole("button", { name: "Check out", exact: true }); + const setup = dialog.getByRole("checkbox", { name: "Run setup script" }); + const script = dialog.getByRole("textbox", { name: "Setup script:" }); + await expect(name).toHaveValue("acme-api-main-wt"); + await branch.fill("review/ledger-batch"); + await name.fill("ledger-review"); + await location.fill("/dev/reviews"); + await setup.check(); + await script.fill("/dev/setup.sh"); + const preview = dialog.getByText("Worktree location: /dev/reviews/ledger-review", { exact: true }); + await expect(preview).toBeVisible(); + + for (const size of [ + { width: 1120, height: 740 }, + { width: 440, height: 520 }, + ]) { + await page.setViewportSize(size); + const column = (await name.boundingBox())!.x; + for (const [label, field] of [ + ["Name:", name], + ["Location:", location], + ["Repository:", repository], + ["Check out:", checkout], + ["Create a new branch", branch], + ["Setup script:", script], + ] as const) { + const caption = dialog.getByText(label, { exact: true }); + await expect(caption).toBeVisible(); + const captionBox = (await caption.boundingBox())!; + const fieldBox = (await field.boundingBox())!; + expect(fieldBox.x, label).toBeCloseTo(column, 0); + expect(captionBox.x + captionBox.width, label).toBeLessThanOrEqual(fieldBox.x); + expect(captionBox.y + captionBox.height / 2, label).toBeCloseTo(fieldBox.y + fieldBox.height / 2, 0); + } + expect((await preview.boundingBox())!.x).toBeCloseTo(column, 0); + } + + await setup.uncheck(); + await expect(script).toHaveCount(0); + await dialog.getByRole("button", { name: "Create", exact: true }).click(); + await expect(dialog).toHaveCount(0); + expect(await ipcCalls(page, "vcs_add_worktree")).toEqual([ + { + repo: "/dev/acme-api", + path: "/dev/reviews/ledger-review", + commitish: "refs/heads/main", + newBranch: "review/ledger-batch", + copyConfig: true, + setup: null, + }, + ]); +}); diff --git a/src/features/vcs/NewWorktreeDialog.tsx b/src/features/vcs/NewWorktreeDialog.tsx index d3a657641..b5b58ccf7 100644 --- a/src/features/vcs/NewWorktreeDialog.tsx +++ b/src/features/vcs/NewWorktreeDialog.tsx @@ -100,6 +100,7 @@ function WorktreeForm({ onRepoChange: (repo: string) => void; }) { const [projectRoot] = useState(() => useProject.getState().project?.root); + const [hasRepositories] = useState(() => useVcs.getState().roots.length > 1); const [data, setData] = useState(); const [sourceRef, setSourceRef] = useState(initialSource); const [createBranch, setCreateBranch] = useState(); @@ -367,128 +368,142 @@ function WorktreeForm({ ]} >
- {!initialSource && ( - { - if (!submitting.current) onRepoChange(next); - }} - /> - )} {main?.submodule && (
{tx("This worktree has its own checkout, separate from the submodule in the parent repository.")}
)} -
- Check out: -
- setBranch(cleanBranch(e))} - /> - )} - - setName(e.target.value)} - /> - -
- setLocation(e.target.value)} - /> - void browse()} /> -
- {parent && folderName &&
{tx`Worktree location: ${target}`}
} -
- - {include && ( - - )} -
- {includeError && ( -
- {includeError} -
- )} - { - setRunSetup(enabled); - setError(undefined); - }} - /> - {runSetup && ( - <> - -
- { - setSetupPath(e.target.value); - setError(undefined); +
+ {!initialSource && hasRepositories && ( + <> + + { + if (!submitting.current) onRepoChange(next); }} /> - void browseSetupScript()} + + )} + + setBranch(cleanBranch(e))} + /> + )} + + setName(e.target.value)} + /> + +
+ setLocation(e.target.value)} + /> + void browse()} /> +
+ {parent && folderName &&
{tx`Worktree location: ${target}`}
} +
+
+ + {include && ( + + )}
- - )} + {includeError && ( +
+ {includeError} +
+ )} + { + setRunSetup(enabled); + setError(undefined); + }} + /> +
+ {runSetup && ( + <> + +
+ { + setSetupPath(e.target.value); + setError(undefined); + }} + /> + void browseSetupScript()} + /> +
+ + )} +
{busy && (
{setupRequest && !skippingSetup ? tx("Creating worktree and running setup…") : tx("Creating worktree…")} diff --git a/src/features/vcs/common.module.css b/src/features/vcs/common.module.css index 831bf7a01..303a73453 100644 --- a/src/features/vcs/common.module.css +++ b/src/features/vcs/common.module.css @@ -791,6 +791,36 @@ align-items: center; gap: var(--space-0-5); } +.worktreeFields { + display: grid; + grid-template-columns: fit-content(44%) minmax(0, 1fr); + align-items: center; + gap: var(--space-2) var(--space-3); +} +.worktreeFields > :not(.worktreeLabel) { + grid-column: 2; + min-width: 0; +} +.worktreeLabel { + grid-column: 1; + min-width: 0; + font-size: var(--fs-ui); + overflow-wrap: anywhere; +} +.worktreeFields > .worktreeOptions { + display: flex; + flex-direction: column; + grid-column: 1 / -1; + gap: var(--space-2); + border-top: 1px solid var(--border); + padding-top: var(--space-2); +} +.worktreeCopyOptions { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: var(--space-1) var(--space-2); +} .worktreeLocation { display: grid; grid-template-columns: minmax(0, 1fr) auto; @@ -801,6 +831,9 @@ color: var(--fg-muted); overflow-wrap: anywhere; } +.worktreeFields > .worktreeTarget { + font-size: var(--fs-small); +} .comparisonDialog > [data-dialog-body] { display: flex; flex-direction: column;