mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
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.
This commit is contained in:
@@ -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);
|
||||
});
|
||||
@@ -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);
|
||||
|
||||
@@ -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 (
|
||||
<div className={clsx(styles.globEditor, !fullWidth && styles.globCompact)}>
|
||||
<div className={clsx(styles.globEditor, !fullWidth && styles.globCompact, className)}>
|
||||
<div className={styles.listToolbar} role="toolbar" aria-controls={listId}>
|
||||
<IconButton icon="plus" title="Add" size="small" onClick={() => void add()} />
|
||||
<IconButton icon="minus" title="Remove" size="small" disabled={selected === null} onClick={remove} />
|
||||
@@ -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 ? (
|
||||
<Input
|
||||
autoFocus
|
||||
mono
|
||||
mono={mono}
|
||||
variant="bare"
|
||||
className={styles.globInput}
|
||||
value={editing.text}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
.spelling .list {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.wordPanel:not([hidden]) {
|
||||
display: grid;
|
||||
gap: var(--space-1-5);
|
||||
padding-top: var(--space-1);
|
||||
}
|
||||
|
||||
.note {
|
||||
margin: 0;
|
||||
color: var(--fg-subtle);
|
||||
font-size: var(--fs-small);
|
||||
line-height: 1.4;
|
||||
}
|
||||
@@ -4,13 +4,15 @@
|
||||
* dictionaries, also filled by the "Save to dictionary" quick fix) and custom
|
||||
* dictionary files.
|
||||
*/
|
||||
import { useId, useState } from "react";
|
||||
import { useSettingsDialog } from "../../model/staging";
|
||||
import { useSetting } from "../../components/context";
|
||||
import { GlobListEditor, Row, Section } from "../../components/Form";
|
||||
import { GlobListEditor, Row, SearchLabel, Section } from "../../components/Form";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { T } from "@/ui";
|
||||
import { T, Tabs } from "@/ui";
|
||||
import type { PageSpec } from "../spec";
|
||||
import styles from "../../components/Form.module.css";
|
||||
import formStyles from "../../components/Form.module.css";
|
||||
import styles from "./Spelling.module.css";
|
||||
|
||||
function NaturalLanguagesPage() {
|
||||
return (
|
||||
@@ -19,7 +21,7 @@ function NaturalLanguagesPage() {
|
||||
label="English (USA, UK)"
|
||||
hint="Bundled Hunspell dictionaries (SCOWL en_US and en_GB) and common programming terms."
|
||||
>
|
||||
<span className={styles.hint}>
|
||||
<span className={formStyles.hint}>
|
||||
<T>Used by Proofreading › Typo</T>
|
||||
</span>
|
||||
</Row>
|
||||
@@ -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<string[]>("spelling.projectWords", "project");
|
||||
const [ideWords, setIdeWords] = useSetting<string[]>("spelling.ideWords", "global");
|
||||
const [dictionaries, setDictionaries] = useSetting<string[]>("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 (
|
||||
<>
|
||||
<Section title="Accepted words">
|
||||
{hasProject && !newProjects && (
|
||||
<Row label="Project dictionary" stacked hint="Stored with the project.">
|
||||
<GlobListEditor
|
||||
aria-label="Project dictionary"
|
||||
value={projectWords ?? []}
|
||||
onChange={(v) => setProjectWords(words(v))}
|
||||
placeholder="word"
|
||||
emptyText="No words"
|
||||
itemLabel="Word"
|
||||
/>
|
||||
</Row>
|
||||
)}
|
||||
<Row label="Application dictionary" stacked hint="Accepted in every project.">
|
||||
<GlobListEditor
|
||||
aria-label="Application dictionary"
|
||||
value={ideWords ?? []}
|
||||
onChange={(v) => setIdeWords(words(v))}
|
||||
placeholder="word"
|
||||
emptyText="No words"
|
||||
itemLabel="Word"
|
||||
/>
|
||||
</Row>
|
||||
</Section>
|
||||
{showProject && (
|
||||
<Tabs
|
||||
items={wordDictionaries}
|
||||
activeId={activeScope}
|
||||
onSelect={setScope}
|
||||
variant="compact"
|
||||
layout="wrap"
|
||||
panelIdPrefix={id}
|
||||
aria-label="Accepted words"
|
||||
/>
|
||||
)}
|
||||
{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 (
|
||||
<div
|
||||
key={scopeId}
|
||||
id={`${id}-panel-${scopeId}`}
|
||||
role={showProject ? "tabpanel" : undefined}
|
||||
aria-labelledby={showProject ? `${id}-tab-${scopeId}` : undefined}
|
||||
hidden={!active}
|
||||
className={styles.wordPanel}
|
||||
>
|
||||
{active && (
|
||||
<>
|
||||
{!showProject && <SearchLabel text={label} />}
|
||||
<GlobListEditor
|
||||
className={styles.list}
|
||||
aria-label={label}
|
||||
value={value ?? []}
|
||||
onChange={(v) => setValue(words(v))}
|
||||
placeholder="word"
|
||||
emptyText="No words"
|
||||
itemLabel="Word"
|
||||
mono={false}
|
||||
/>
|
||||
<p className={styles.note}>
|
||||
<T>{hint}</T>
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function SpellingPage() {
|
||||
const [dictionaries, setDictionaries] = useSetting<string[]>("spelling.customDictionaries", "global");
|
||||
return (
|
||||
<div className={styles.spelling}>
|
||||
<Section title="Custom dictionaries">
|
||||
<Row
|
||||
label="Dictionary files"
|
||||
@@ -68,6 +110,7 @@ function SpellingPage() {
|
||||
hint="Plain-text word lists (one word per line) or Hunspell .dic files; a .dic with its .aff beside it also accepts the inflected forms and compounds its rules allow. Relative paths resolve against the project root, ~/ against the home folder."
|
||||
>
|
||||
<GlobListEditor
|
||||
className={styles.list}
|
||||
aria-label="Custom dictionaries"
|
||||
value={dictionaries ?? []}
|
||||
onChange={(v) => setDictionaries(words(v))}
|
||||
@@ -77,7 +120,10 @@ function SpellingPage() {
|
||||
/>
|
||||
</Row>
|
||||
</Section>
|
||||
</>
|
||||
<Section title="Accepted words">
|
||||
<AcceptedWords />
|
||||
</Section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user