fix(settings): align Gutter Icons in a preview list (#4702)

Gutter Icons puts its five options in one bordered list under the master checkbox, each with a representative icon or color swatch, aligned checkboxes and labels at the standard settings font size, keeping search matches visible in a narrow pane.
This commit is contained in:
l0ng-ai
2026-11-20 14:28:25 +08:00
committed by GitHub
parent 2bb93366bb
commit 84cdfa2136
3 changed files with 135 additions and 42 deletions
+37
View File
@@ -0,0 +1,37 @@
import { expect, test } from "./fixtures";
test("gutter icon previews align in narrow settings and the master switch keeps each choice", async ({
workbench: page,
}) => {
await page.keyboard.press("Meta+,");
const settings = page.getByRole("dialog", { name: "Settings", exact: true });
await settings.getByRole("textbox", { name: "Search settings" }).fill("Color preview");
await settings.getByRole("treeitem", { name: "Gutter Icons", exact: true }).click();
await page.setViewportSize({ width: 520, height: 620 });
const list = settings.getByRole("list", { name: "Gutter Icons", exact: true });
await expect(list.getByRole("listitem")).toHaveCount(5);
await expect(list.locator("mark")).toHaveText(["Color", "preview"]);
const layout = await list.getByRole("listitem").evaluateAll((rows) =>
rows.map((row) => {
const preview = row.firstElementChild!.getBoundingClientRect();
const input = row.querySelector("input")!.getBoundingClientRect();
return { x: input.x, previewRight: preview.right, overflow: row.scrollWidth - row.clientWidth };
}),
);
for (const row of layout) {
expect(row.previewRight).toBeLessThan(row.x);
expect(row.x).toBeCloseTo(layout[0]!.x, 0);
expect(row.overflow).toBeLessThanOrEqual(1);
}
const master = settings.getByRole("checkbox", { name: "Show gutter icons", exact: true });
const color = list.getByRole("checkbox", { name: "Color preview", exact: true });
await color.uncheck();
await master.uncheck();
for (const option of await list.getByRole("checkbox").all()) await expect(option).toBeDisabled();
await master.check();
await expect(color).toBeEnabled();
await expect(color).not.toBeChecked();
await expect(list.getByRole("checkbox", { name: "Bookmarks", exact: true })).toBeChecked();
});
@@ -120,6 +120,48 @@
opacity: 0.5;
}
.gutterIconList {
margin: var(--space-2) 0 0;
padding: var(--space-1);
list-style: none;
border: 1px solid var(--border);
border-radius: var(--radius-small);
background: var(--bg-field);
font-size: var(--fs-ui);
}
.gutterIconRow {
display: flex;
align-items: center;
gap: var(--space-2);
padding-inline: var(--space-2);
border-radius: var(--radius-selection);
}
.gutterIconRow:has(input:enabled):hover {
background: var(--bg-hover);
}
.gutterIconPreview {
display: grid;
flex: 0 0 16px;
place-items: center;
}
.gutterIconRow:has(input:disabled) .gutterIconPreview {
opacity: 0.5;
}
.gutterIconRow .gutterIconChoice {
flex: 1;
min-width: 0;
min-height: var(--h-list-row);
padding-block: var(--space-0-5);
overflow-wrap: anywhere;
}
.gutterSwatch {
width: 12px;
height: 12px;
border: 1px solid var(--border-strong);
border-radius: var(--radius-small);
background: var(--accent);
}
/* Font page */
.fontPage {
height: 100%;
+56 -42
View File
@@ -8,9 +8,10 @@
import { useEffect, useId, useState } from "react";
import clsx from "clsx";
import { commands, isTauri } from "@/platform/ipc";
import { Checkbox } from "@/ui";
import { Checkbox, Icon, type IconName } from "@/ui";
import { SearchLabel, Select } from "../../components/Form";
import { useLabelMatch, useSetting } from "../../components/context";
import { useLabelMatch, useSearchQuery, useSetting } from "../../components/context";
import { labelMatches } from "../../model/pages";
import { editorPage, type Item } from "./kit";
import styles from "./Editor.module.css";
import { tx } from "@/platform/i18n";
@@ -625,6 +626,29 @@ function CloseButtonPosition() {
);
}
const GUTTER_OPTIONS: ReadonlyArray<{ id: string; label: string; icon?: IconName; keywords?: string[] }> = [
{
id: "run",
label: "Run configurations and tests",
icon: "gutter-run",
keywords: ["Run", "run configurations", "test"],
},
{ id: "bookmarks", label: "Bookmarks", icon: "bookmark" },
{
id: "inheritors",
label: "Implemented and overridden declarations",
icon: "gutter-implemented",
keywords: ["Implemented and overridden", "implementations", "subclasses", "inheritors"],
},
{
id: "supers",
label: "Implementing and overriding methods",
icon: "gutter-implementing",
keywords: ["Implementing and overriding", "super method", "overrides", "implements"],
},
{ id: "colors", label: "Color preview", keywords: ["color", "swatch", "colour"] },
];
const GUTTER = editorPage({
id: "editor.general.gutterIcons",
title: "Gutter Icons",
@@ -632,56 +656,46 @@ const GUTTER = editorPage({
sections: [
{
items: [
{ t: "check", key: `${P}.showGutterIcons`, label: "Show gutter icons" },
{
t: "check",
key: `${P}.showGutterIcons`,
label: "Show gutter icons",
children: [
{
t: "custom",
label: "Run",
keywords: ["run configurations", "test"],
component: () => <GutterGroup id="run" label="Run configurations and tests" />,
},
{ t: "custom", label: "Bookmarks", component: () => <GutterGroup id="bookmarks" label="Bookmarks" /> },
{
t: "custom",
label: "Implemented and overridden",
keywords: ["implementations", "subclasses", "inheritors"],
component: () => <GutterGroup id="inheritors" label="Implemented and overridden declarations" />,
},
{
t: "custom",
label: "Implementing and overriding",
keywords: ["super method", "overrides", "implements"],
component: () => <GutterGroup id="supers" label="Implementing and overriding methods" />,
},
{
t: "custom",
label: "Color preview",
keywords: ["color", "swatch", "colour"],
component: () => <GutterGroup id="colors" label="Color preview" />,
},
],
t: "custom",
label: "Gutter Icons",
keywords: GUTTER_OPTIONS.flatMap(({ label, keywords }) => [label, ...(keywords ?? [])]),
component: GutterIconList,
},
],
},
],
});
function GutterGroup({ id, label }: { id: string; label: string }) {
function GutterIconList() {
const [disabled, set] = useSetting<string[]>(`${P}.gutterIconsDisabled`);
const [master] = useSetting<boolean>(`${P}.showGutterIcons`);
const matched = useLabelMatch(label);
const query = useSearchQuery();
return (
<div className={matched ? `${styles.check} ${styles.matched}` : styles.check}>
<Checkbox
checked={!disabled.includes(id)}
disabled={!master}
label={<SearchLabel text={label} />}
onChange={(on) => set(on ? disabled.filter((x) => x !== id) : [...disabled, id])}
/>
</div>
<ul role="list" aria-label={tx("Gutter Icons")} className={styles.gutterIconList}>
{GUTTER_OPTIONS.map(({ id, label, icon }) => {
const matched = labelMatches(label, query);
return (
<li
key={id}
className={clsx(styles.gutterIconRow, matched && styles.matched)}
data-search-match={matched || undefined}
>
<span className={styles.gutterIconPreview} aria-hidden>
{icon ? <Icon name={icon} size={16} /> : <span className={styles.gutterSwatch} />}
</span>
<Checkbox
className={styles.gutterIconChoice}
checked={!disabled.includes(id)}
disabled={!master}
label={<SearchLabel text={label} />}
onChange={(on) => set(on ? disabled.filter((x) => x !== id) : [...disabled, id])}
/>
</li>
);
})}
</ul>
);
}