fix(settings): align the Appearance controls (#4867)

fix(settings): align the Appearance controls
This commit is contained in:
l0ng-ai
2026-11-21 07:20:18 +08:00
committed by GitHub
parent 0ceda2c385
commit f284633162
3 changed files with 142 additions and 75 deletions
+74
View File
@@ -0,0 +1,74 @@
import { expect, test } from "./fixtures";
test("Appearance keeps themes and UI font controls grouped across Settings widths", async ({ workbench: page }) => {
await page.setViewportSize({ width: 1120, height: 800 });
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("Use custom font");
await dialog.getByRole("treeitem", { name: "Appearance", exact: true }).click();
await search.clear();
const theme = dialog.getByRole("button", { name: "Theme", exact: true });
const sync = dialog.getByRole("checkbox", { name: "Sync with OS", exact: true });
const preferences = dialog.getByRole("button", { name: "Preferred themes", exact: true });
const more = dialog.getByRole("button", { name: "Get more themes", exact: true });
const font = dialog.getByRole("combobox", { name: "UI font", exact: true });
const fallback = dialog.getByRole("combobox", { name: "UI fallback font", exact: true });
const size = dialog.getByRole("textbox", { name: "UI font size", exact: true });
const custom = dialog.getByRole("checkbox", { name: "Use custom font:", exact: true });
await expect(preferences).toBeDisabled();
await expect(font).toBeDisabled();
await expect(size).toBeDisabled();
await expect(fallback).toBeDisabled();
const [themeBox, gearBox, linkBox, fontBox, sizeBox, fallbackBox] = await Promise.all(
[theme, preferences, more, font, size, fallback].map((control) => control.boundingBox()),
);
if (!themeBox || !gearBox || !linkBox || !fontBox || !sizeBox || !fallbackBox) {
throw new Error("Missing Appearance control bounds");
}
expect(linkBox.y).toBeGreaterThan(themeBox.y + themeBox.height);
expect(gearBox.x).toBeGreaterThan(themeBox.x + themeBox.width);
expect(gearBox.y + gearBox.height / 2).toBeCloseTo(themeBox.y + themeBox.height / 2, 0);
expect(sizeBox.y).toBeCloseTo(fontBox.y, 0);
expect(sizeBox.x).toBeGreaterThan(fontBox.x + fontBox.width);
expect(fallbackBox.x).toBeCloseTo(fontBox.x, 0);
expect(fallbackBox.y).toBeGreaterThan(fontBox.y);
await sync.check();
await expect(theme).toBeDisabled();
for (const width of [580, 520]) {
await page.setViewportSize({ width, height: 800 });
await preferences.click();
const popup = page.getByRole("dialog", { name: "Preferred themes", exact: true });
const light = popup.getByRole("button", { name: "Preferred light theme", exact: true });
const dark = popup.getByRole("button", { name: "Preferred dark theme", exact: true });
await expect(light).toBeInViewport({ ratio: 1 });
await expect(dark).toBeInViewport({ ratio: 1 });
const [lightBox, darkBox] = await Promise.all([light.boundingBox(), dark.boundingBox()]);
if (!lightBox || !darkBox) throw new Error("Missing preferred theme bounds");
expect(lightBox.x).toBeCloseTo(darkBox.x, 0);
expect(lightBox.width).toBeCloseTo(darkBox.width, 0);
await page.keyboard.press("Escape");
await expect(popup).toBeHidden();
for (const field of [font, size, fallback]) await expect(field).toBeInViewport({ ratio: 1 });
const [narrowFont, narrowSize, narrowFallback] = await Promise.all(
[font, size, fallback].map((control) => control.boundingBox()),
);
if (!narrowFont || !narrowSize || !narrowFallback) throw new Error("Missing narrow font control bounds");
expect(narrowSize.y).toBeGreaterThan(narrowFont.y);
expect(narrowFallback.x).toBeCloseTo(narrowFont.x, 0);
}
await custom.check();
await font.fill("Inter");
await size.fill("15");
await fallback.fill("Noto Sans CJK SC");
await fallback.press("Enter");
await expect(font).toHaveValue("Inter");
await expect(size).toHaveValue("15");
await expect(fallback).toHaveValue("Noto Sans CJK SC");
await dialog.getByRole("button", { name: "Cancel", exact: true }).click();
await expect(dialog).toBeHidden();
});
+28 -22
View File
@@ -1,13 +1,11 @@
.inline {
.themeSync {
display: inline-flex;
align-items: center;
gap: var(--space-2);
margin-left: 8px;
padding: 0 4px;
border-radius: var(--radius-row);
}
.themeSelect {
flex: 1 1 120px;
flex: 1 1 140px;
min-width: min(120px, 100%);
max-width: 180px;
}
@@ -30,10 +28,16 @@
color: var(--fg-subtle);
overflow-wrap: anywhere;
}
.popupBody {
display: flex;
flex-direction: column;
padding: 8px 14px;
.preferredThemes {
width: min(440px, calc(100vw - var(--space-4)));
padding: var(--space-2) var(--space-3);
}
.preferredThemes label {
white-space: normal;
overflow-wrap: anywhere;
}
.preferredThemes button {
width: 100%;
}
/* Inline option groups, with custom font controls wrapping together. */
@@ -47,33 +51,35 @@
margin: 0 -6px;
border-radius: var(--radius-row);
}
/* Custom font block (IDEA Appearance): labels share one column, so the UI font,
fallback and Size controls all start at the same x. */
.customFontRow {
display: grid;
grid-template-columns: max-content minmax(0, 1fr);
grid-template-columns: fit-content(42%) minmax(0, 280px) max-content;
align-items: start;
column-gap: var(--space-2);
row-gap: var(--space-1);
min-height: 28px;
min-height: var(--h-field);
padding: 2px 6px;
margin: 0 -6px;
border-radius: var(--radius-row);
}
.customFontRow > .fontLabel {
padding-top: 3px;
white-space: nowrap;
}
.customFontRow > .fontCheck {
white-space: nowrap;
}
.fontControl {
.fontLabel,
.fontCheck,
.fontSize {
display: flex;
align-items: center;
min-height: var(--h-field);
min-width: 0;
}
.sizeInput {
width: 64px;
.fontSize {
gap: var(--space-2);
}
@container settings-content (max-width: 580px) {
.customFontRow {
grid-template-columns: fit-content(42%) minmax(0, 280px);
}
.fontSize {
grid-column: 2;
}
}
.disabled {
color: var(--fg-subtle);
+40 -53
View File
@@ -98,7 +98,14 @@ function ThemeRow() {
showPicked(shown);
};
return (
<Row label="Theme">
<Row
label="Theme"
hint={
<button type="button" className={styles.link} onClick={() => selectPage("plugins#themes")}>
<T>Get more themes</T>
</button>
}
>
<Select<ConcreteTheme>
value={shown}
options={themeSelectOptions(choices, shown)}
@@ -108,11 +115,7 @@ function ThemeRow() {
className={styles.themeSelect}
disabled={sync}
/>
{/* As in IntelliJ IDEA: most themes are plugins, so point at the marketplace's. */}
<button type="button" className={styles.link} onClick={() => selectPage("plugins#themes")}>
<T>Get more themes</T>
</button>
<span className={clsx(styles.inline, matched && styles.matched)}>
<span className={clsx(styles.themeSync, matched && styles.matched)}>
<Checkbox
checked={sync}
onChange={(on) => {
@@ -141,7 +144,7 @@ function ThemeRow() {
offset={4}
aria-label="Preferred themes"
>
<div className={styles.popupBody}>
<FormGroup className={styles.preferredThemes}>
<Row label="Preferred theme for light OS mode">
<Select<ConcreteTheme>
value={light}
@@ -158,7 +161,7 @@ function ThemeRow() {
aria-label="Preferred dark theme"
/>
</Row>
</div>
</FormGroup>
</Popup>
</Row>
);
@@ -260,53 +263,37 @@ function CustomFontRow() {
const [size, setSize] = useSetting<number>("appearance.uiFontSize");
const id = useId();
const matched = useLabelMatch("Use custom font");
// Labels share one column (IDEA Appearance): the UI font, fallback and Size
// controls all start at the same x instead of drifting with flex wrapping.
return (
<div className={clsx(styles.customFontRow, matched && styles.matched)}>
<span className={styles.fontCheck}>
<Checkbox checked={on} onChange={setOn} label={<SearchLabel text="Use custom font:" />} />
</span>
<span className={styles.fontControl}>
<FontPicker label="UI font" disabled={!on} value={family} onChange={setFamily} />
</span>
<FontPicker label="UI font" disabled={!on} value={family} onChange={setFamily} />
<div className={clsx(styles.fontSize, !on && styles.disabled)}>
<label htmlFor={`${id}-size`}>
<SearchLabel text="Size:" />
</label>
<NumberInput
id={`${id}-size`}
value={size}
onChange={setSize}
{...LIMITS.uiFontSize}
integer
disabled={!on}
aria-label="UI font size"
/>
</div>
<label className={clsx(styles.fontLabel, !on && styles.disabled)} htmlFor={`${id}-fallback`}>
<SearchLabel text="Fallback font:" />
</label>
<span className={styles.fontControl}>
<FontPicker
id={`${id}-fallback`}
label="UI fallback font"
disabled={!on}
value={fallback}
onChange={setFallback}
allowEmpty
/>
</span>
<label className={clsx(styles.fontLabel, !on && styles.disabled)} htmlFor={`${id}-size`}>
<SearchLabel text="Size:" />
</label>
<span className={styles.fontControl}>
{on ? (
<NumberInput
id={`${id}-size`}
value={size}
onChange={setSize}
{...LIMITS.uiFontSize}
integer
aria-label="UI font size"
/>
) : (
<Input
id={`${id}-size`}
className={styles.sizeInput}
value={String(size)}
disabled
aria-label="UI font size"
readOnly
/>
)}
</span>
<FontPicker
id={`${id}-fallback`}
label="UI fallback font"
disabled={!on}
value={fallback}
onChange={setFallback}
allowEmpty
/>
</div>
);
}
@@ -919,6 +906,12 @@ export const BEHAVIOR_PAGES: PageSpec[] = [
},
{ kind: "custom", label: "Accent color", keywords: ["accent colour", "highlight"], component: AccentRow },
{ kind: "custom", label: "Different tool window background", component: ToolWindowBackgroundRow },
{
kind: "custom",
label: "Use custom font",
keywords: ["UI font size", "Size", "font family", "fallback font"],
component: CustomFontRow,
},
],
},
{
@@ -936,12 +929,6 @@ export const BEHAVIOR_PAGES: PageSpec[] = [
title: "Accessibility",
options: [
{ kind: "custom", label: "Zoom", keywords: ["scale", "zoom ide"], component: ZoomRow },
{
kind: "custom",
label: "Use custom font",
keywords: ["UI font size", "Size", "font family", "fallback font"],
component: CustomFontRow,
},
{ kind: "toggle", key: "appearance.contrastScrollbars", label: "Use contrast scrollbars" },
{
kind: "toggle",