diff --git a/e2e/gutterIconsLayout.spec.ts b/e2e/gutterIconsLayout.spec.ts new file mode 100644 index 000000000..bb9c595ad --- /dev/null +++ b/e2e/gutterIconsLayout.spec.ts @@ -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(); +}); diff --git a/src/features/settings/pages/editor/Editor.module.css b/src/features/settings/pages/editor/Editor.module.css index 5da757583..64bbb7244 100644 --- a/src/features/settings/pages/editor/Editor.module.css +++ b/src/features/settings/pages/editor/Editor.module.css @@ -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%; diff --git a/src/features/settings/pages/editor/general.tsx b/src/features/settings/pages/editor/general.tsx index d4337d195..c94874a20 100644 --- a/src/features/settings/pages/editor/general.tsx +++ b/src/features/settings/pages/editor/general.tsx @@ -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: () => , - }, - { t: "custom", label: "Bookmarks", component: () => }, - { - t: "custom", - label: "Implemented and overridden", - keywords: ["implementations", "subclasses", "inheritors"], - component: () => , - }, - { - t: "custom", - label: "Implementing and overriding", - keywords: ["super method", "overrides", "implements"], - component: () => , - }, - { - t: "custom", - label: "Color preview", - keywords: ["color", "swatch", "colour"], - component: () => , - }, - ], + 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(`${P}.gutterIconsDisabled`); const [master] = useSetting(`${P}.showGutterIcons`); - const matched = useLabelMatch(label); + const query = useSearchQuery(); return ( -
- } - onChange={(on) => set(on ? disabled.filter((x) => x !== id) : [...disabled, id])} - /> -
+
    + {GUTTER_OPTIONS.map(({ id, label, icon }) => { + const matched = labelMatches(label, query); + return ( +
  • + + {icon ? : } + + } + onChange={(on) => set(on ? disabled.filter((x) => x !== id) : [...disabled, id])} + /> +
  • + ); + })} +
); }