From 7dbfe8852e435043e7eb82dc5c037bc422e5ba65 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sat, 21 Nov 2026 07:22:13 +0800 Subject: [PATCH] fix(settings): align the Spelling settings layout (#4884) Place custom dictionary files above the accepted words. Give both lists the available pane width, with monospaced paths and standard UI text for words. A tab selects the project or application dictionary within the accepted words section. Settings for New Projects shows the application dictionary directly. --- e2e/spellingSettingsLayout.spec.ts | 76 ++++++++++++ .../settings/components/Form.module.css | 4 +- src/features/settings/components/Form.tsx | 10 +- .../settings/pages/editor/Spelling.module.css | 18 +++ .../settings/pages/editor/spelling.tsx | 108 +++++++++++++----- 5 files changed, 181 insertions(+), 35 deletions(-) create mode 100644 e2e/spellingSettingsLayout.spec.ts create mode 100644 src/features/settings/pages/editor/Spelling.module.css diff --git a/e2e/spellingSettingsLayout.spec.ts b/e2e/spellingSettingsLayout.spec.ts new file mode 100644 index 000000000..49b0a3f72 --- /dev/null +++ b/e2e/spellingSettingsLayout.spec.ts @@ -0,0 +1,76 @@ +import { expect, ipcCalls, stubDesktop, test } from "./fixtures"; + +test("Spelling puts dictionary files first and keeps accepted words in separate scopes", async ({ + workbench: page, +}) => { + await page.setViewportSize({ width: 1120, height: 820 }); + await stubDesktop(page); + await page.evaluate(() => { + window.__ipc.handlers.settings_get_global = () => ({}); + window.__ipc.handlers.settings_get = () => ({}); + window.__ipc.handlers.settings_set = () => ({}); + }); + await page.keyboard.press("Meta+,"); + const settings = page.getByRole("dialog", { name: "Settings", exact: true }); + const search = settings.getByRole("textbox", { name: "Search settings" }); + await search.fill("Spelling"); + await settings.getByRole("treeitem", { name: "Spelling", exact: true }).click(); + await search.clear(); + + const files = settings.getByRole("region", { name: "Custom dictionaries", exact: true }); + const words = settings.getByRole("region", { name: "Accepted words", exact: true }); + const filesList = files.getByRole("listbox", { name: "Custom dictionaries", exact: true }); + const project = words.getByRole("tab", { name: "Project dictionary", exact: true }); + const application = words.getByRole("tab", { name: "Application dictionary", exact: true }); + for (const width of [1120, 580, 520]) { + await page.setViewportSize({ width, height: 820 }); + const [filesBox, wordsBox] = await Promise.all([files.boundingBox(), words.boundingBox()]); + if (!filesBox || !wordsBox) throw new Error("Missing Spelling sections"); + expect(filesBox.y + filesBox.height).toBeLessThan(wordsBox.y); + const [paths, accepted] = await Promise.all([filesList.boundingBox(), words.getByRole("listbox").boundingBox()]); + if (!paths || !accepted) throw new Error("Missing dictionary lists"); + expect(paths.width).toBeCloseTo(accepted.width, 0); + if (width === 1120) expect(paths.width).toBeGreaterThan(480); + await expect(project).toBeInViewport({ ratio: 1 }); + await expect(application).toBeInViewport({ ratio: 1 }); + } + + await files.getByRole("button", { name: "Add", exact: true }).click(); + await files.getByRole("textbox", { name: "Dictionary path" }).fill("dictionaries/team.dic"); + await files.getByRole("textbox", { name: "Dictionary path" }).press("Enter"); + await expect(filesList.getByRole("option", { name: "dictionaries/team.dic" })).toBeVisible(); + + await expect(project).toHaveAttribute("aria-selected", "true"); + await words.getByRole("button", { name: "Add", exact: true }).click(); + await words.getByRole("textbox", { name: "Word", exact: true }).fill("checkoutable"); + await words.getByRole("textbox", { name: "Word", exact: true }).press("Enter"); + await project.press("ArrowRight"); + await expect(application).toHaveAttribute("aria-selected", "true"); + await expect(words.getByRole("option", { name: "checkoutable" })).toHaveCount(0); + await words.getByRole("button", { name: "Add", exact: true }).click(); + await words.getByRole("textbox", { name: "Word", exact: true }).fill("worktree"); + await words.getByRole("textbox", { name: "Word", exact: true }).press("Enter"); + + await project.click(); + await expect(words.getByRole("option", { name: "checkoutable" })).toBeVisible(); + await expect(words.getByRole("option", { name: "worktree" })).toHaveCount(0); + expect(await ipcCalls(page, "settings_set")).toEqual([]); + await settings.getByRole("button", { name: "Apply", exact: true }).click(); + await expect + .poll(async () => (await ipcCalls(page, "settings_set")).sort((a, b) => String(a.key).localeCompare(String(b.key)))) + .toEqual([ + { scope: "global", key: "spelling.customDictionaries", value: JSON.stringify(["dictionaries/team.dic"]) }, + { scope: "global", key: "spelling.ideWords", value: JSON.stringify(["worktree"]) }, + { scope: "project", key: "spelling.projectWords", value: JSON.stringify(["checkoutable"]) }, + ]); + await settings.getByRole("button", { name: "Cancel", exact: true }).click(); + await page.evaluate(async () => { + const actionModule = "/src/platform/actions.ts"; + const { executeAction } = await import(/* @vite-ignore */ actionModule); + await executeAction("file.newProjectsSettings", "editor.naturalLanguages.spelling"); + }); + const defaults = page.getByRole("dialog", { name: "Settings for New Projects", exact: true }); + await expect(defaults.getByRole("listbox", { name: "Application dictionary", exact: true })).toBeVisible(); + await expect(defaults.getByRole("tablist", { name: "Accepted words" })).toHaveCount(0); + await expect(defaults.getByRole("listbox", { name: "Project dictionary", exact: true })).toHaveCount(0); +}); diff --git a/src/features/settings/components/Form.module.css b/src/features/settings/components/Form.module.css index 327a1d5ab..f3c069b05 100644 --- a/src/features/settings/components/Form.module.css +++ b/src/features/settings/components/Form.module.css @@ -232,9 +232,11 @@ align-items: center; height: var(--h-row); padding: 0 8px; - font-family: var(--font-mono); color: var(--fg); } +.globMono { + font-family: var(--font-mono); +} .globSelected { background: var(--bg-selected); color: var(--fg-strong); diff --git a/src/features/settings/components/Form.tsx b/src/features/settings/components/Form.tsx index ed6eada39..249714319 100644 --- a/src/features/settings/components/Form.tsx +++ b/src/features/settings/components/Form.tsx @@ -307,6 +307,8 @@ export function ColorSwatches({ value, presets, onChange, allowCustom = true, .. export interface GlobListEditorProps { value: readonly string[]; onChange: (value: string[]) => void; + className?: string; + mono?: boolean; placeholder?: string; "aria-label"?: string; /** Shown for an empty list. */ @@ -322,6 +324,8 @@ export interface GlobListEditorProps { export function GlobListEditor({ value, onChange, + className, + mono = true, placeholder = "**/pattern", emptyText = "No patterns", itemLabel = "Pattern", @@ -406,7 +410,7 @@ export function GlobListEditor({ const rows = editing && editing.index >= value.length ? [...value, ""] : value; return ( -
+
void add()} /> @@ -439,14 +443,14 @@ export function GlobListEditor({ id={`${listId}-${i}`} role="option" aria-selected={selected === i} - className={clsx(styles.globRow, selected === i && styles.globSelected)} + className={clsx(styles.globRow, mono && styles.globMono, selected === i && styles.globSelected)} onMouseDown={() => setSelected(i)} onDoubleClick={() => setEditing({ index: i, text: glob })} > {editing?.index === i ? ( - + Used by Proofreading › Typo @@ -29,38 +31,78 @@ function NaturalLanguagesPage() { const words = (list: readonly string[]) => [...new Set(list.map((w) => w.trim()).filter(Boolean))]; -function SpellingPage() { +const wordDictionaries = [ + { id: "project", label: "Project dictionary", hint: "Stored with the project." }, + { id: "application", label: "Application dictionary", hint: "Accepted in every project." }, +]; + +function AcceptedWords() { const hasProject = useProject((s) => !!s.project); const newProjects = useSettingsDialog((s) => s.newProjects); const [projectWords, setProjectWords] = useSetting("spelling.projectWords", "project"); const [ideWords, setIdeWords] = useSetting("spelling.ideWords", "global"); - const [dictionaries, setDictionaries] = useSetting("spelling.customDictionaries", "global"); + const [scope, setScope] = useState("project"); + const id = useId(); + const showProject = hasProject && !newProjects; + const scopes = showProject ? wordDictionaries : wordDictionaries.slice(1); + const activeScope = showProject ? scope : "application"; + return ( <> -
- {hasProject && !newProjects && ( - - setProjectWords(words(v))} - placeholder="word" - emptyText="No words" - itemLabel="Word" - /> - - )} - - setIdeWords(words(v))} - placeholder="word" - emptyText="No words" - itemLabel="Word" - /> - -
+ {showProject && ( + + )} + {scopes.map(({ id: scopeId, label, hint }) => { + const isProject = scopeId === "project"; + const active = activeScope === scopeId; + const value = isProject ? projectWords : ideWords; + const setValue = isProject ? setProjectWords : setIdeWords; + return ( + + ); + })} + + ); +} + +function SpellingPage() { + const [dictionaries, setDictionaries] = useSetting("spelling.customDictionaries", "global"); + return ( +
setDictionaries(words(v))} @@ -77,7 +120,10 @@ function SpellingPage() { />
- +
+ +
+
); }