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.
This commit is contained in:
l0ng-ai
2026-11-20 15:39:03 +08:00
committed by GitHub
parent af0e9c9a55
commit 330d45279b
8 changed files with 274 additions and 65 deletions
+68
View File
@@ -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 } },
]);
});
+102
View File
@@ -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;
}
@@ -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(<VcsDialogHost />);
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"]);
});
-24
View File
@@ -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;
+94 -35
View File
@@ -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 }]}
>
<div className={styles.form}>
<div className={remoteStyles.content}>
<RepoPicker repo={repo} onChange={setRepo} />
{/* Keyed: picking another repository starts a fresh list, so answers for the previous one are dropped. */}
<RemotesList key={repo} repo={repo} />
@@ -595,35 +601,82 @@ function RemotesList({ repo }: { repo: string | null }) {
};
const current = remotes.find((r) => r.name === selected);
const onRowKey = (event: KeyboardEvent<HTMLTableRowElement>, 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 (
<>
<div className={styles.manageBar} role="toolbar" aria-label={tx("Remotes")}>
<IconButton icon="plus" title="Add Remote…" size="small" onClick={() => edit()} />
<IconButton icon="minus" title="Remove Remote" size="small" disabled={!current} onClick={() => void remove()} />
<IconButton icon="edit" title="Edit Remote…" size="small" disabled={!current} onClick={() => edit(current)} />
<div className={remoteStyles.panel}>
<div className={remoteStyles.toolbar} role="toolbar" aria-label={tx("Remotes")}>
<IconButton icon="plus" title="Add Remote…" size="small" onClick={() => edit()} />
<IconButton
icon="minus"
title="Remove Remote"
size="small"
disabled={!current}
onClick={() => void remove()}
/>
<IconButton icon="edit" title="Edit Remote…" size="small" disabled={!current} onClick={() => edit(current)} />
</div>
<div className={remoteStyles.scroller}>
<table className={remoteStyles.table} role="grid" aria-label={tx("Remotes")}>
<colgroup>
<col className={remoteStyles.nameColumn} />
<col />
</colgroup>
<thead>
<tr>
<th scope="col">
<T>Name</T>
</th>
<th scope="col">
<T>URL</T>
</th>
</tr>
</thead>
<tbody>
{!remotes.length && (
<tr>
<td colSpan={2} className={styles.empty}>
<T>No remotes</T>
</td>
</tr>
)}
{remotes.map((r) => (
<tr
key={r.name}
aria-selected={r.name === selected}
tabIndex={r.name === selected ? 0 : -1}
onFocus={() => setSelected(r.name)}
onClick={(e) => e.currentTarget.focus({ preventScroll: true })}
onDoubleClick={() => edit(r)}
onKeyDown={(e) => onRowKey(e, r)}
>
<td title={r.name}>{r.name}</td>
<td title={r.url}>{r.url}</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
<div className={styles.choiceList} role="listbox" aria-label={tx("Remotes")}>
{!remotes.length && (
<div className={styles.empty}>
<T>No remotes</T>
</div>
)}
{remotes.map((r) => (
<button
key={r.name}
type="button"
role="option"
aria-selected={r.name === selected}
className={clsx(styles.manageRow, r.name === selected && styles.manageRowSelected)}
onClick={() => setSelected(r.name)}
onDoubleClick={() => edit(r)}
>
<span className={styles.fileName}>{r.name}</span>
<span className={clsx(styles.fileDir, styles.mono)}>{r.url}</span>
</button>
))}
</div>
{error && <div className={styles.error}>{error}</div>}
{error && (
<div className={clsx(styles.error, remoteStyles.error)} role="alert">
{error}
</div>
)}
</>
);
}
@@ -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({
]}
>
<form
className={styles.form}
className={remoteStyles.editor}
onSubmit={(e) => {
e.preventDefault();
submit();
}}
>
<label className={styles.fieldLabel}>
<label htmlFor={nameId}>
<T>Name:</T>
</label>
<Input data-autofocus aria-label="Name" value={name} onChange={(e) => setName(e.target.value)} />
<label className={styles.fieldLabel}>
<Input id={nameId} data-autofocus aria-label="Name" value={name} onChange={(e) => setName(e.target.value)} />
<label htmlFor={urlId}>
<T>URL:</T>
</label>
<Input aria-label="URL" mono value={url} onChange={(e) => setUrl(e.target.value)} />
{error && (name || url) && <div className={styles.error}>{error}</div>}
<Input id={urlId} aria-label="URL" mono value={url} onChange={(e) => setUrl(e.target.value)} />
{error && (name || url) && (
<div className={clsx(styles.error, remoteStyles.error)} role="alert">
{error}
</div>
)}
</form>
</Dialog>
);
+1
View File
@@ -262,6 +262,7 @@ describe("catalogs", () => {
"12288 MB",
"16384 MB",
"Docker",
"URL",
"Code Vision",
"JUnit",
"⌘Enter",
+1
View File
@@ -873,6 +873,7 @@
"Add Classes Directory": "Add Classes Directory",
"Name:": "Name:",
"URL:": "URL:",
"URL": "URL",
"Startup script:": "Startup script:",
"Port:": "Port:",
"New server Tomcat Home": "New server Tomcat Home",
+1
View File
@@ -3138,6 +3138,7 @@
"UI font size": "UI 字体大小",
"Uninstalled {name}": "已卸载 {name}",
"URL:": "URL:",
"URL": "URL",
"The controls show the scheme's actual appearance; changes override it.": "控件显示方案的实际外观;修改即覆盖方案。",
"Uncommitted": "未提交",
"Uncommitted changes are stashed before the update and restored afterwards.": "更新前会储藏未提交的更改,并在之后恢复。",