fix(settings): align the Terminal settings layout (#4882)

Group the primary font, fallback font, and sizing controls above Application Settings. Let the start directory and default tab name use the available width. Keep the shell path, installed-shell menu, and Browse button together. Narrow windows place text fields below their labels and show the application checkboxes in one column.
This commit is contained in:
l0ng-ai
2026-11-21 07:21:17 +08:00
committed by GitHub
parent 0af7bcc7cf
commit 4340a96c59
3 changed files with 266 additions and 105 deletions
+92
View File
@@ -0,0 +1,92 @@
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
test("Terminal settings keep shell controls and font groups readable as the window narrows", async ({
workbench: page,
}) => {
await page.setViewportSize({ width: 1120, height: 900 });
await stubDesktop(page);
const shellPath = "C:/Program Files/Shell/bin/bash.exe";
await page.evaluate((path) => {
window.__ipc.handlers.settings_get_global = () => ({});
window.__ipc.handlers.term_default_shell = () => "/bin/zsh";
window.__ipc.handlers.term_available_shells = () => ["/bin/zsh", path];
}, shellPath);
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("Shell path");
await dialog.getByRole("treeitem", { name: "Terminal", exact: true }).click();
await search.clear();
const directory = dialog.getByRole("textbox", { name: /^Start directory:?$/ });
const shell = dialog.getByRole("textbox", { name: /^Shell path:?$/ });
const tab = dialog.getByRole("textbox", { name: /^Default Tab name:?$/ });
const shells = dialog.getByRole("button", { name: "Installed Shells", exact: true });
const browse = dialog.getByRole("button", { name: "Browse", exact: true });
const font = dialog.getByRole("combobox", { name: "Terminal font", exact: true });
const fallback = dialog.getByRole("combobox", { name: "Terminal fallback font", exact: true });
const size = dialog.getByRole("textbox", { name: "Terminal font size", exact: true });
const lineHeight = dialog.getByRole("textbox", { name: "Terminal line height", exact: true });
const column = dialog.getByRole("textbox", { name: "Terminal column width", exact: true });
const bell = dialog.getByRole("checkbox", { name: "Audible bell", exact: true });
const shortcuts = dialog.getByRole("checkbox", { name: "Override IDE shortcuts", exact: true });
await expect(shell).toHaveAttribute("placeholder", "/bin/zsh");
for (const width of [1120, 580, 520]) {
await page.setViewportSize({ width, height: 900 });
await shell.scrollIntoViewIfNeeded();
await expect(shells).toBeInViewport({ ratio: 1 });
await expect(browse).toBeInViewport({ ratio: 1 });
const [dir, command, name, menu, chooseFile, main, secondary, fontSize, line, col, left, right] = await Promise.all(
[directory, shell, tab, shells, browse, font, fallback, size, lineHeight, column, bell, shortcuts].map(
(control) => control.boundingBox(),
),
);
if (
!dir ||
!command ||
!name ||
!menu ||
!chooseFile ||
!main ||
!secondary ||
!fontSize ||
!line ||
!col ||
!left ||
!right
)
throw new Error("Missing Terminal settings bounds");
expect(command.y + command.height / 2).toBeCloseTo(menu.y + menu.height / 2, 0);
expect(menu.y).toBeCloseTo(chooseFile.y, 0);
expect(command.width).toBeGreaterThan(100);
expect(command.x).toBeCloseTo(name.x, 0);
expect(chooseFile.x + chooseFile.width).toBeCloseTo(name.x + name.width, 0);
expect(dir.x + dir.width).toBeCloseTo(name.x + name.width, 0);
expect(main.y).toBeLessThan(command.y);
if (width === 1120) {
expect(main.y).toBeCloseTo(secondary.y, 0);
expect(fontSize.y).toBeCloseTo(line.y, 0);
expect(fontSize.y).toBeCloseTo(col.y, 0);
expect(right.x).toBeGreaterThan(left.x);
} else {
expect(command.x).toBeCloseTo(dir.x, 0);
expect(secondary.y).toBeGreaterThan(main.y);
expect(right.x).toBeCloseTo(left.x, 0);
expect(right.y).toBeGreaterThan(left.y);
}
}
await shells.click();
await page.getByRole("menuitemcheckbox", { name: shellPath, exact: true }).click();
await expect(shell).toHaveValue(`"${shellPath}"`);
await expect(font).toBeDisabled();
await dialog.getByRole("checkbox", { name: "Use editor font", exact: true }).uncheck();
await font.fill("Cascadia Mono");
await size.fill("15");
await expect(font).toHaveValue("Cascadia Mono");
await expect(size).toHaveValue("15");
await dialog.getByRole("button", { name: "Cancel", exact: true }).click();
await expect(dialog).toBeHidden();
expect(await ipcCalls(page, "settings_set")).toEqual([]);
});
@@ -0,0 +1,58 @@
.field,
.shellControls {
width: 100%;
}
.shellControls {
display: flex;
align-items: center;
gap: var(--space-1);
min-width: 0;
}
.shellControls > input {
flex: 1;
min-width: 0;
}
.families {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(265px, 100%), 1fr));
column-gap: var(--space-4);
}
.fontPicker {
display: flex;
flex-direction: column;
gap: var(--space-1);
min-width: 0;
}
.metrics {
display: flex;
flex-wrap: wrap;
column-gap: var(--space-4);
}
.metrics > div {
margin-inline: 0;
padding-inline: 0;
}
.options > div:first-child {
grid-template-columns: repeat(auto-fit, minmax(min(245px, 100%), 1fr));
}
@container settings-content (max-width: 440px) {
section .textRow[class] {
grid-template-columns: minmax(0, 1fr);
}
.textRow > label {
padding-top: 0;
}
.textRow > :last-child {
grid-column: 1;
}
}
+116 -105
View File
@@ -22,8 +22,9 @@ import { selectPage, setQuery } from "../model/staging";
import { MirrorPrefixRow } from "./DownloadSources";
import { MCP_SERVER_PAGE } from "./mcpServer";
import type { PageSpec } from "./spec";
import { BoundToggle, Grid, Indented, PageLink, TableEditor } from "./workflowControls";
import { BoundToggle, Grid, PageLink, TableEditor } from "./workflowControls";
import styles from "./Workflow.module.css";
import terminalStyles from "./TerminalSettings.module.css";
import { tx } from "@/platform/i18n";
import { TERMINAL_MAX_FPS_OPTIONS } from "@/platform/workflowSettings";
@@ -62,29 +63,27 @@ const isMac = typeof navigator !== "undefined" && /Mac/i.test(navigator.platform
// ---------------------------------------------------------------------------
// Terminal
function TextSetting({
function TerminalTextSetting({
k,
label,
placeholder,
hint,
width = "wide",
mono,
}: {
k: string;
label: string;
placeholder?: string;
hint?: ReactNode;
width?: "wide" | "medium";
mono?: boolean;
}) {
const [value, set] = useSetting<string>(k);
const id = useId();
return (
<Row label={label} htmlFor={id} hint={hint}>
<Row label={label} htmlFor={id} hint={hint} className={terminalStyles.textRow}>
<Input
id={id}
mono={mono}
className={styles[width]}
className={terminalStyles.field}
value={value}
placeholder={placeholder}
onChange={(e) => set(e.target.value)}
@@ -95,7 +94,7 @@ function TextSetting({
function StartDirectoryRow() {
return (
<TextSetting
<TerminalTextSetting
k="terminal.startDirectory"
label="Start directory"
placeholder="Project root"
@@ -148,25 +147,35 @@ function ShellPathRow() {
label="Shell path"
htmlFor={id}
hint="A command line, e.g. /bin/zsh --login. Leave empty to use the login shell."
className={terminalStyles.textRow}
>
<Input
id={id}
mono
className={styles.wide}
value={value}
placeholder={detected ?? "Login shell"}
onChange={(e) => set(e.target.value)}
/>
<IconButton
ref={menuRef}
icon="chevron-down"
size="small"
title="Installed Shells"
aria-haspopup="menu"
aria-expanded={open}
disabled={shells.length === 0}
onClick={() => setOpen((o) => !o)}
/>
<div className={terminalStyles.shellControls}>
<Input
id={id}
mono
value={value}
placeholder={detected ?? "Login shell"}
onChange={(e) => set(e.target.value)}
/>
<IconButton
ref={menuRef}
icon="chevron-down"
size="small"
title="Installed Shells"
aria-haspopup="menu"
aria-expanded={open}
disabled={shells.length === 0}
onClick={() => setOpen((o) => !o)}
/>
<IconButton
icon="folder-open"
size="small"
title="Browse…"
aria-label="Browse"
disabled={!isTauri()}
onClick={() => void browse()}
/>
</div>
<Menu
open={open}
onClose={() => setOpen(false)}
@@ -175,14 +184,6 @@ function ShellPathRow() {
aria-label="Installed shells"
items={shells.map((p) => ({ id: p, label: p, checked: quotePath(p) === value, run: () => set(quotePath(p)) }))}
/>
<IconButton
icon="folder-open"
size="small"
title="Browse…"
aria-label="Browse"
disabled={!isTauri()}
onClick={() => void browse()}
/>
</Row>
);
}
@@ -225,41 +226,45 @@ function TerminalKeybindingsLink() {
function TerminalOptions() {
return (
<Grid
left={
<>
<BoundToggle k="terminal.audibleBell" label="Audible bell" />
<BoundToggle k="terminal.closeOnExit" label="Close session when it ends" />
<BoundToggle k="terminal.mouseReporting" label="Mouse reporting" />
<BoundToggle k="terminal.copyOnSelection" label="Copy to clipboard on selection" />
<BoundToggle k="terminal.pasteOnMiddleClick" label="Paste on middle mouse button click" />
<BoundToggle
k="terminal.escapeToEditor"
label="Move focus to the Editor with Escape"
hint="Otherwise Escape goes to the shell."
/>
</>
}
right={
<>
<BoundToggle
k="terminal.overrideIdeShortcuts"
label="Override IDE shortcuts"
hint={<TerminalKeybindingsLink />}
/>
<BoundToggle k="terminal.shellIntegration" label="Shell integration" />
<BoundToggle k="terminal.highlightHyperlinks" label="Highlight hyperlinks" />
<BoundToggle k="terminal.highlightSelection" label="Highlight occurrences of selected text" />
{isMac && <BoundToggle k="terminal.optionAsMeta" label="Use Option as Meta key" />}
<SettingSelect
k="terminal.maxFps"
label="Maximum refresh rate"
hint="Caps how often fast terminal output is painted. Hidden windows always paint more slowly."
options={TERMINAL_MAX_FPS_OPTIONS}
/>
</>
}
/>
<>
<div className={terminalStyles.options}>
<Grid
left={
<>
<BoundToggle k="terminal.audibleBell" label="Audible bell" />
<BoundToggle k="terminal.closeOnExit" label="Close session when it ends" />
<BoundToggle k="terminal.mouseReporting" label="Mouse reporting" />
<BoundToggle k="terminal.copyOnSelection" label="Copy to clipboard on selection" />
<BoundToggle k="terminal.pasteOnMiddleClick" label="Paste on middle mouse button click" />
<BoundToggle
k="terminal.escapeToEditor"
label="Move focus to the Editor with Escape"
hint="Otherwise Escape goes to the shell."
/>
</>
}
right={
<>
<BoundToggle
k="terminal.overrideIdeShortcuts"
label="Override IDE shortcuts"
hint={<TerminalKeybindingsLink />}
/>
<BoundToggle k="terminal.shellIntegration" label="Shell integration" />
<BoundToggle k="terminal.highlightHyperlinks" label="Highlight hyperlinks" />
<BoundToggle k="terminal.highlightSelection" label="Highlight occurrences of selected text" />
{isMac && <BoundToggle k="terminal.optionAsMeta" label="Use Option as Meta key" />}
</>
}
/>
</div>
<SettingSelect
k="terminal.maxFps"
label="Maximum refresh rate"
hint="Caps how often fast terminal output is painted. Hidden windows always paint more slowly."
options={TERMINAL_MAX_FPS_OPTIONS}
/>
</>
);
}
@@ -285,9 +290,9 @@ function TerminalFont() {
</PageLink>
</span>
</div>
<Indented>
<Row label="Font">
<span className={styles.fontFamily}>
<div className={terminalStyles.families}>
<Row label="Font" stacked>
<span className={terminalStyles.fontPicker}>
<FontPicker
value={family}
onChange={setFamily}
@@ -305,6 +310,11 @@ function TerminalFont() {
</span>
</span>
</Row>
<Row label="Fallback font" stacked hint="Used for characters the main font lacks.">
<FontPicker value={fallback} onChange={setFallback} allowEmpty label="Terminal fallback font" />
</Row>
</div>
<div className={terminalStyles.metrics}>
<Row label="Size">
<NumberInput
value={size}
@@ -315,28 +325,25 @@ function TerminalFont() {
aria-label="Terminal font size"
/>
</Row>
</Indented>
<Row label="Line height">
<NumberInput
value={lineHeight}
onChange={setLineHeight}
{...L.terminalLineHeight}
step={0.1}
aria-label="Terminal line height"
/>
</Row>
<Row label="Fallback font" hint="Used for characters the main font lacks.">
<FontPicker value={fallback} onChange={setFallback} allowEmpty label="Terminal fallback font" />
</Row>
<Row label="Column width">
<NumberInput
value={columnWidth}
onChange={setColumnWidth}
{...L.terminalColumnWidth}
step={0.1}
aria-label="Terminal column width"
/>
</Row>
<Row label="Line height">
<NumberInput
value={lineHeight}
onChange={setLineHeight}
{...L.terminalLineHeight}
step={0.1}
aria-label="Terminal line height"
/>
</Row>
<Row label="Column width">
<NumberInput
value={columnWidth}
onChange={setColumnWidth}
{...L.terminalColumnWidth}
step={0.1}
aria-label="Terminal column width"
/>
</Row>
</div>
</>
);
}
@@ -636,11 +643,26 @@ export const TOOLS_PAGES: PageSpec[] = [
{ kind: "custom", label: "Environment variables", keywords: ["env"], component: EnvRow },
],
},
{
title: "Font",
options: [
{
kind: "custom",
label: "Use editor font",
keywords: ["Font", "Show only monospaced fonts", "Size", "Line height", "Fallback font", "Column width"],
component: TerminalFont,
},
],
},
{
title: "Application Settings",
options: [
{ kind: "custom", label: "Shell path", component: ShellPathRow },
{ kind: "text", key: "terminal.tabName", label: "Default Tab name", placeholder: "Local" },
{
kind: "custom",
label: "Default Tab name",
component: () => <TerminalTextSetting k="terminal.tabName" label="Default Tab name" placeholder="Local" />,
},
{
kind: "select",
key: "terminal.appTitleAsTabName",
@@ -673,17 +695,6 @@ export const TOOLS_PAGES: PageSpec[] = [
},
],
},
{
title: "Font",
options: [
{
kind: "custom",
label: "Use editor font",
keywords: ["Font", "Show only monospaced fonts", "Size", "Line height", "Fallback font", "Column width"],
component: TerminalFont,
},
],
},
],
},
{