From 330d45279b349ce9b355c094d540eb5bd276e55c Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Fri, 20 Nov 2026 15:39:03 +0800 Subject: [PATCH] Align the Git Remotes table and edit form (#4724) Git Remotes uses dedicated Name and URL columns with a fixed header; long values keep their own space and show in full on hover. The list scrolls inside a resizable dialog with the toolbar and footer in view, keyboard selection brings the row into view, and the edit form aligns both labels beside their fields. --- e2e/gitRemotesLayout.spec.ts | 68 +++++++++ src/features/vcs/GitRemotes.module.css | 102 ++++++++++++++ .../vcs/__tests__/remotesDialogRepo.test.tsx | 13 +- src/features/vcs/common.module.css | 24 ---- src/features/vcs/gitMenuDialogs.tsx | 129 +++++++++++++----- src/platform/i18n.test.ts | 1 + src/platform/locales/text/en.json | 1 + src/platform/locales/text/zh.json | 1 + 8 files changed, 274 insertions(+), 65 deletions(-) create mode 100644 e2e/gitRemotesLayout.spec.ts create mode 100644 src/features/vcs/GitRemotes.module.css diff --git a/e2e/gitRemotesLayout.spec.ts b/e2e/gitRemotesLayout.spec.ts new file mode 100644 index 000000000..6ca808fc3 --- /dev/null +++ b/e2e/gitRemotesLayout.spec.ts @@ -0,0 +1,68 @@ +import type { Remote, RemoteEdit } from "../src/bindings"; +import { expect, ipcCalls, stubDesktop, test } from "./fixtures"; + +test("keeps remote columns, actions and editing usable in a short window", async ({ workbench: page }) => { + await page.setViewportSize({ width: 450, height: 420 }); + await stubDesktop(page); + const originalUrl = "https://git.example.test/engineering/international-settlement/replica-18.git"; + await page.evaluate(async (originalUrl) => { + let remotes: Remote[] = Array.from({ length: 18 }, (_, i) => ({ + name: i === 0 ? "origin" : `mirror-${i + 1}`, + url: i === 17 ? originalUrl : `https://git.example.test/project/repository-${i + 1}.git`, + })); + window.__ipc.handlers.vcs_remotes = () => remotes; + window.__ipc.handlers.vcs_edit_remote = ({ edit }) => { + const patch = edit as RemoteEdit; + if (patch.op === "edit") { + remotes = remotes.map((remote) => + remote.name === patch.name ? { name: patch.new_name, url: patch.url } : remote, + ); + } + return null; + }; + window.__ipc.handlers.vcs_branches = () => []; + const module = "/src/features/vcs/gitMenuDialogs.tsx"; + const { showManageRemotes } = await import(/* @vite-ignore */ module); + showManageRemotes(); + }, originalUrl); + + const dialog = page.getByRole("dialog", { name: "Git Remotes", exact: true }); + await expect(dialog.getByText(originalUrl, { exact: true })).toBeVisible(); + const table = dialog.getByRole("grid", { name: "Remotes", exact: true }); + const name = table.getByRole("columnheader", { name: "Name", exact: true }); + const url = table.getByRole("columnheader", { name: "URL", exact: true }); + await expect(name).toBeInViewport({ ratio: 1 }); + await expect(url).toBeInViewport({ ratio: 1 }); + const first = table.getByRole("row", { name: /^origin / }); + const last = table.getByRole("row", { name: /^mirror-18 / }); + await first.click(); + await page.keyboard.press("End"); + await expect(last).toBeFocused(); + await expect(last).toHaveAttribute("aria-selected", "true"); + await expect(last).toBeInViewport({ ratio: 1 }); + await expect(url).toBeInViewport({ ratio: 1 }); + const cell = last.getByRole("gridcell", { name: originalUrl, exact: true }); + await expect(cell).toHaveAttribute("title", originalUrl); + expect((await cell.boundingBox())!.x).toBeCloseTo((await url.boundingBox())!.x, 0); + const scroller = table.locator(".."); + expect(await scroller.evaluate((el) => el.scrollTop)).toBeGreaterThan(0); + expect(await scroller.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1); + await expect(dialog.getByRole("button", { name: "Add Remote…" })).toBeInViewport({ ratio: 1 }); + await expect(dialog.getByRole("button", { name: "OK", exact: true })).toBeInViewport({ ratio: 1 }); + + await page.keyboard.press("Enter"); + const edit = page.getByRole("dialog", { name: "Edit Remote", exact: true }); + const editName = edit.getByRole("textbox", { name: "Name", exact: true }); + const editUrl = edit.getByRole("textbox", { name: "URL", exact: true }); + await expect(editName).toHaveValue("mirror-18"); + await expect(editUrl).toHaveValue(originalUrl); + expect((await editName.boundingBox())!.x).toBeCloseTo((await editUrl.boundingBox())!.x, 0); + const nextUrl = "https://git.example.test/repository-18.git"; + await editUrl.fill(nextUrl); + await edit.getByRole("button", { name: "OK", exact: true }).click(); + await expect(last).toContainText(nextUrl); + await expect(last).toBeFocused(); + expect(await ipcCalls(page, "vcs_edit_remote")).toMatchObject([ + { edit: { op: "edit", name: "mirror-18", new_name: "mirror-18", url: nextUrl } }, + ]); +}); diff --git a/src/features/vcs/GitRemotes.module.css b/src/features/vcs/GitRemotes.module.css new file mode 100644 index 000000000..298588b89 --- /dev/null +++ b/src/features/vcs/GitRemotes.module.css @@ -0,0 +1,102 @@ +.dialog { + height: 380px; +} + +.dialog > [data-dialog-body] { + display: flex; + flex-direction: column; +} + +.content { + display: flex; + flex: 1; + flex-direction: column; + gap: var(--space-2); + min-height: 0; + padding: var(--space-3) var(--space-4); +} + +.panel { + display: flex; + flex: 1; + flex-direction: column; + min-height: calc(var(--h-list-row) * 4); + overflow: hidden; + border: 1px solid var(--border-popup); + border-radius: var(--radius-small); +} + +.toolbar { + display: flex; + flex: none; + gap: var(--space-1); + padding: var(--space-1) var(--space-2); + border-bottom: 1px solid var(--border-popup); +} + +.scroller { + flex: 1; + min-height: 0; + overflow: auto; + scrollbar-gutter: stable; + scroll-padding-block-start: var(--h-list-row); +} + +.table { + width: 100%; + table-layout: fixed; + border-spacing: 0; + font-size: var(--fs-ui); +} + +.nameColumn { + width: 30%; +} + +.table th, +.table td { + height: var(--h-list-row); + overflow: hidden; + padding: 0 var(--space-2); + text-align: start; + text-overflow: ellipsis; + white-space: nowrap; +} + +.table th { + position: sticky; + z-index: 1; + top: 0; + background: var(--bg-popup); + box-shadow: inset 0 -1px var(--border-popup); + color: var(--fg-subtle); + font-weight: 500; +} + +.table tr[aria-selected]:hover { + background: var(--bg-hover); +} + +.table tr[aria-selected="true"] { + background: var(--bg-tree-selected); + color: var(--fg-strong); +} + +.table tr:focus-visible { + outline: 1px solid var(--focus-ring); + outline-offset: -1px; +} + +.editor { + display: grid; + grid-template-columns: max-content minmax(0, 1fr); + align-items: center; + gap: var(--space-2) var(--space-3); + padding: var(--space-3) var(--space-4); + font-size: var(--fs-ui); +} + +.error { + grid-column: 1 / -1; + overflow-wrap: anywhere; +} diff --git a/src/features/vcs/__tests__/remotesDialogRepo.test.tsx b/src/features/vcs/__tests__/remotesDialogRepo.test.tsx index aad0f1e23..e6b876c8e 100644 --- a/src/features/vcs/__tests__/remotesDialogRepo.test.tsx +++ b/src/features/vcs/__tests__/remotesDialogRepo.test.tsx @@ -57,7 +57,8 @@ const addRemote = async (name: string, url: string) => { fireEvent.click(screen.getAllByRole("button", { name: "OK" }).at(-1)!); }; -const options = () => screen.queryAllByRole("option").map((o) => o.textContent); +const remotes = () => screen.getAllByRole("row").filter((row) => row.hasAttribute("aria-selected")); +const remoteText = () => remotes().map((row) => row.textContent); it("offers no repository choice when the project has one repository", async () => { useVcs.setState({ roots: ["/p"], repo: null }); @@ -79,13 +80,13 @@ it("lists and edits the remotes of the repository picked in the dialog", async ( render(); await act(() => showManageRemotes()); expect(screen.getByRole("button", { name: "Repository" })).toHaveTextContent("a"); - await waitFor(() => expect(options()).toEqual(["origingit@example.com:a.git"])); + await waitFor(() => expect(remoteText()).toEqual(["origingit@example.com:a.git"])); await pick("Repository", "b"); expect(screen.getByRole("button", { name: "Repository" })).toHaveTextContent("b"); - await waitFor(() => expect(options()).toEqual(["upstreamgit@example.com:b.git", "forkgit@example.com:me/b.git"])); + await waitFor(() => expect(remoteText()).toEqual(["upstreamgit@example.com:b.git", "forkgit@example.com:me/b.git"])); // The first remote of the picked repository is selected. - expect(screen.getByRole("option", { name: /upstream/ })).toHaveAttribute("aria-selected", "true"); + expect(screen.getByRole("row", { name: /upstream/ })).toHaveAttribute("aria-selected", "true"); // "origin" exists only in a, so the name is free in b. await addRemote("origin", "git@example.com:b.git"); @@ -103,8 +104,8 @@ it("ignores the remotes of a repository that is no longer picked", async () => { await act(() => showManageRemotes()); await pick("Repository", "b"); - await waitFor(() => expect(options()).toHaveLength(2)); + await waitFor(() => expect(remotes()).toHaveLength(2)); // a's remotes arrive after b was picked: they must not replace b's. await act(async () => resolveA([remote("origin", "git@example.com:a.git")])); - expect(options()).toEqual(["upstreamgit@example.com:b.git", "forkgit@example.com:me/b.git"]); + expect(remoteText()).toEqual(["upstreamgit@example.com:b.git", "forkgit@example.com:me/b.git"]); }); diff --git a/src/features/vcs/common.module.css b/src/features/vcs/common.module.css index dacc55d56..c3104e97d 100644 --- a/src/features/vcs/common.module.css +++ b/src/features/vcs/common.module.css @@ -687,35 +687,11 @@ grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-1) var(--space-3); } -/* Manage Remotes / Worktrees lists. */ .manageBar { display: flex; align-items: center; gap: var(--space-0-5); } -.manageRow { - width: 100%; - height: var(--h-row); - display: flex; - align-items: center; - gap: 10px; - padding: 0 8px; - border: none; - background: none; - color: var(--fg); - font: inherit; - text-align: left; - white-space: nowrap; - overflow: hidden; - cursor: default; -} -.manageRow:hover { - background: var(--bg-hover); -} -.manageRowSelected, -.manageRowSelected:hover { - background: var(--bg-list-selected); -} /* Worktrees dialog: the tree needs a height of its own inside the auto-sized body. */ .worktreeListDialog { height: 340px; diff --git a/src/features/vcs/gitMenuDialogs.tsx b/src/features/vcs/gitMenuDialogs.tsx index 589e0752d..438c818e5 100644 --- a/src/features/vcs/gitMenuDialogs.tsx +++ b/src/features/vcs/gitMenuDialogs.tsx @@ -1,5 +1,5 @@ /** Git menu dialogs: Pull…, Merge…, Rebase…, Manage Remotes… and Worktrees. */ -import { useEffect, useMemo, useRef, useState } from "react"; +import { useEffect, useId, useMemo, useRef, useState, type KeyboardEvent } from "react"; import clsx from "clsx"; import type { Branch, BranchInfo, MergeOptions, Remote, Worktree } from "@/bindings"; import { call, commands } from "@/platform/ipc"; @@ -17,6 +17,7 @@ import { Select, T, Tree, + listNavigate, useSanitizedField, type SelectOption, type SelectProps, @@ -36,6 +37,7 @@ import { type RepoWorktrees, } from "./worktrees"; import styles from "./common.module.css"; +import remoteStyles from "./GitRemotes.module.css"; import pullStyles from "./PullDialog.module.css"; import { tx } from "@/platform/i18n"; import { useProject } from "@/platform/project"; @@ -530,10 +532,14 @@ function RemotesDialog({ onClose }: { onClose: () => void }) { open title="Git Remotes" onClose={onClose} - width={560} + width={600} + minWidth={360} + minHeight={280} + resizable="both" + className={remoteStyles.dialog} buttons={[{ label: "OK", role: "default", autoFocus: true, onClick: onClose }]} > -
+
{/* Keyed: picking another repository starts a fresh list, so answers for the previous one are dropped. */} @@ -595,35 +601,82 @@ function RemotesList({ repo }: { repo: string | null }) { }; const current = remotes.find((r) => r.name === selected); + const onRowKey = (event: KeyboardEvent, remote: Remote) => { + if (event.key === "Enter") { + event.preventDefault(); + edit(remote); + return; + } + const row = event.currentTarget; + const index = listNavigate(event.key, { items: remotes, active: row.sectionRowIndex }); + if (index === null) return; + event.preventDefault(); + const target = row.closest("tbody")?.rows.item(index); + target?.focus({ preventScroll: true }); + target?.scrollIntoView({ block: "nearest", inline: "nearest" }); + }; + return ( <> -
- edit()} /> - void remove()} /> - edit(current)} /> +
+
+ edit()} /> + void remove()} + /> + edit(current)} /> +
+
+ + + + + + + + + + + + + {!remotes.length && ( + + + + )} + {remotes.map((r) => ( + setSelected(r.name)} + onClick={(e) => e.currentTarget.focus({ preventScroll: true })} + onDoubleClick={() => edit(r)} + onKeyDown={(e) => onRowKey(e, r)} + > + + + + ))} + +
+ Name + + URL +
+ No remotes +
{r.name}{r.url}
+
-
- {!remotes.length && ( -
- No remotes -
- )} - {remotes.map((r) => ( - - ))} -
- {error &&
{error}
} + {error && ( +
+ {error} +
+ )} ); } @@ -639,6 +692,8 @@ function RemoteEditDialog({ }) { const [name, setName] = useState(remote?.name ?? (existing.includes("origin") ? "" : "origin")); const [url, setUrl] = useState(remote?.url ?? ""); + const nameId = useId(); + const urlId = useId(); const error = validateRemoteName(name, existing) ?? (url.trim() ? null : "Enter the remote URL"); const submit = () => { if (!error) onDone({ name: name.trim(), url: url.trim() }); @@ -655,21 +710,25 @@ function RemoteEditDialog({ ]} >
{ e.preventDefault(); submit(); }} > -