fix(settings): align the Git settings controls (#4865)

fix(settings): align the Git settings controls
This commit is contained in:
l0ng-ai
2026-11-21 07:20:07 +08:00
committed by GitHub
parent 8b3f55dfb4
commit 0ceda2c385
3 changed files with 168 additions and 45 deletions
+65
View File
@@ -0,0 +1,65 @@
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
test("Git settings keep the executable and Test button together at narrow widths", async ({ workbench: page }) => {
await page.setViewportSize({ width: 560, height: 740 });
await stubDesktop(page);
const gitPath = "C:/Program Files/Git/cmd/git.exe";
const longPath = `C:/${"long-directory-name".repeat(20)}/git.exe`;
await page.evaluate(
({ gitPath, longPath }) => {
window.__ipc.handlers.vcs_detected_git = () => gitPath;
window.__ipc.handlers.vcs_git_version = ({ path }) => ({ path: path || longPath, version: "git version 2.49.0" });
window.__ipc.handlers.git_credentials = () => [];
},
{ gitPath, longPath },
);
await page.keyboard.press("Meta+,");
const dialog = page.getByRole("dialog", { name: "Settings", exact: true });
const search = dialog.getByRole("textbox", { name: "Search settings" });
await search.fill("Path to Git executable");
await dialog.getByRole("treeitem", { name: "Git", exact: true }).click();
await search.clear();
const path = dialog.getByRole("textbox", { name: /^Path to Git executable:?$/ });
const testButton = dialog.getByRole("button", { name: "Test", exact: true });
const branches = dialog.getByRole("textbox", { name: /^Protected branches:?$/ });
await expect(path).toHaveAttribute("placeholder", `Auto-detected: ${gitPath}`);
for (const width of [560, 580, 1120]) {
await page.setViewportSize({ width, height: 740 });
await path.scrollIntoViewIfNeeded();
const [field, button, patterns] = await Promise.all([
path.boundingBox(),
testButton.boundingBox(),
branches.boundingBox(),
]);
if (!field || !button || !patterns) throw new Error("Missing Git settings control bounds");
expect(field.y).toBeCloseTo(button.y, 0);
if (width <= 580) {
const label = await dialog.getByText("Path to Git executable", { exact: true }).boundingBox();
if (!label) throw new Error("Missing Git executable label bounds");
expect(label.y + label.height).toBeLessThan(field.y);
expect(field.width).toBeGreaterThan(150);
}
expect(field.x + field.width).toBeLessThan(button.x);
expect(button.x + button.width).toBeCloseTo(patterns.x + patterns.width, 0);
}
await page.setViewportSize({ width: 560, height: 740 });
await testButton.click();
const result = dialog.getByRole("status").filter({ hasText: "Git version is 2.49.0" });
await expect(result).toContainText(longPath);
await expect(result).toBeInViewport({ ratio: 1 });
await path.fill(gitPath);
await expect(result).toHaveCount(0);
await testButton.click();
await expect(result).toContainText(gitPath);
expect(await ipcCalls(page, "vcs_git_version")).toEqual([{ path: "" }, { path: gitPath }]);
expect(await ipcCalls(page, "settings_set")).toEqual([]);
const update = dialog.getByRole("radiogroup", { name: "Update method" });
const merge = update.getByRole("radio", { name: "Merge" });
const rebase = update.getByRole("radio", { name: "Rebase" });
await expect(merge).toBeChecked();
await merge.press("ArrowRight");
await expect(rebase).toBeChecked();
});
@@ -0,0 +1,38 @@
.executableControls {
display: flex;
align-items: center;
gap: var(--space-2);
width: 100%;
min-width: 0;
}
.executableControls > input {
flex: 1;
min-width: 0;
}
.testResult {
display: block;
overflow-wrap: anywhere;
}
.branchPatterns {
width: 100%;
}
.updateMethods {
display: flex;
flex-wrap: wrap;
gap: var(--space-1) var(--space-4);
}
@container settings-content (max-width: 440px) {
.executable > div {
grid-template-columns: minmax(0, 1fr);
row-gap: var(--space-1);
}
.executable > div > div {
grid-column: 1;
}
}
+65 -45
View File
@@ -10,14 +10,15 @@ import { call, commands, isTauri, onIdeEvent } from "@/platform/ipc";
import { useProject } from "@/platform/project";
import { WORKFLOW_LIMITS, type IssueLinkValid, type VcsSettingsValid } from "@/platform/workflowSettings";
import { showInFileManagerLabel } from "@/platform/fileManager";
import { Button, Icon, IconButton, Input, rowSelectionMode, Select, selectRow, type SelectOption, T } from "@/ui";
import { Button, Icon, IconButton, Input, Radio, rowSelectionMode, Select, selectRow, type SelectOption, T } from "@/ui";
import { choosePath } from "@/platform/choosePath";
import { Row, SettingSelect } from "../components/Form";
import { Row, SearchLabel, SettingSelect } from "../components/Form";
import { useSetting } from "../components/context";
import type { AgentModelCatalog, AgentProvider } from "@/bindings";
import type { PageSpec } from "./spec";
import { BoundToggle, Grid, Indented, RadioRow, TableEditor, ToggleNumber } from "./workflowControls";
import styles from "./Workflow.module.css";
import gitStyles from "./GitSettings.module.css";
import { tx } from "@/platform/i18n";
const L = WORKFLOW_LIMITS;
@@ -296,32 +297,35 @@ function GitExecutableRow() {
}
};
return (
<Row
label="Path to Git executable"
htmlFor={id}
hint={
result ? (
<span className={result.ok ? styles.ok : styles.error} role="status">
{result.text}
</span>
) : undefined
}
>
<Input
id={id}
mono
className={styles.wide}
value={path}
placeholder={detected ? tx`Auto-detected: ${detected}` : "Auto-detected"}
onChange={(e) => {
setPath(e.target.value);
setResult(null);
}}
/>
<Button size="small" disabled={testing || !isTauri()} onClick={() => void test()}>
<T>Test</T>
</Button>
</Row>
<div className={gitStyles.executable}>
<Row
label="Path to Git executable"
htmlFor={id}
hint={
result ? (
<span className={clsx(gitStyles.testResult, result.ok ? styles.ok : styles.error)} role="status">
{result.text}
</span>
) : undefined
}
>
<div className={gitStyles.executableControls}>
<Input
id={id}
mono
value={path}
placeholder={detected ? tx`Auto-detected: ${detected}` : "Auto-detected"}
onChange={(e) => {
setPath(e.target.value);
setResult(null);
}}
/>
<Button disabled={testing || !isTauri()} onClick={() => void test()}>
<T>Test</T>
</Button>
</div>
</Row>
</div>
);
}
@@ -334,7 +338,7 @@ function ProtectedBranchesRow() {
htmlFor={id}
hint="Force push is not allowed to these branches. Separate patterns with ; (wildcards * and ? are supported)."
>
<Input id={id} className={styles.medium} value={value} onChange={(e) => set(e.target.value)} />
<Input id={id} className={gitStyles.branchPatterns} value={value} onChange={(e) => set(e.target.value)} />
</Row>
);
}
@@ -435,6 +439,31 @@ function PushDialogRows() {
);
}
function GitUpdateMethodRow() {
const [method, setMethod] = useSetting<"merge" | "rebase">("vcs.git.updateMethod");
const name = useId();
return (
<div>
<Row label="Update method">
<div className={gitStyles.updateMethods} role="radiogroup" aria-label={tx("Update method")}>
<Radio
name={name}
checked={method === "merge"}
onChange={() => setMethod("merge")}
label={<SearchLabel text="Merge" />}
/>
<Radio
name={name}
checked={method === "rebase"}
onChange={() => setMethod("rebase")}
label={<SearchLabel text="Rebase" />}
/>
</div>
</Row>
</div>
);
}
const PATCH_CREATED: SelectOption[] = [
{ value: "ask", label: "Ask" },
{ value: "no", label: "No" },
@@ -918,12 +947,6 @@ export const VCS_PAGES: PageSpec[] = [
key: "vcs.git.warnDetachedHead",
label: "Warn when committing in detached HEAD or during rebase",
},
{
kind: "toggle",
key: "vcs.git.signOff",
label: "Sign-off commit",
hint: "Adds a Signed-off-by trailer by default; it can still be switched per commit in Commit Options.",
},
{
kind: "custom",
label: "Warn when committing files larger than",
@@ -935,6 +958,12 @@ export const VCS_PAGES: PageSpec[] = [
key: "vcs.git.warnBadFileNames",
label: "Warn when committing files with names that might cause issues on other systems",
},
{
kind: "toggle",
key: "vcs.git.signOff",
label: "Sign-off commit",
hint: "Adds a Signed-off-by trailer by default; it can still be switched per commit in Commit Options.",
},
],
},
{
@@ -961,16 +990,7 @@ export const VCS_PAGES: PageSpec[] = [
kind: "custom",
label: "Update method",
keywords: ["Merge", "Rebase", "pull"],
component: () => (
<RadioRow
k="vcs.git.updateMethod"
label="Update method"
choices={[
{ value: "merge", label: "Merge" },
{ value: "rebase", label: "Rebase" },
]}
/>
),
component: GitUpdateMethodRow,
},
{
kind: "custom",