From dac4db09940eec3b6ff6a0d1594e5653791b8505 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Fri, 20 Nov 2026 11:13:08 +0800 Subject: [PATCH] fix(settings): separate file type associations from ignore rules (#4657) File Types settings separate file type associations from ignore rules. Verified with e2e fileTypesLayout, settings/locales vitest and typecheck. --- e2e/fileTypesLayout.spec.ts | 62 ++++++++ .../settings/pages/FileTypes.module.css | 50 ++++-- src/features/settings/pages/FileTypes.tsx | 150 ++++++++++-------- src/features/settings/pages/builtins.tsx | 105 ++++++++++-- src/platform/locales/text/en.json | 1 + src/platform/locales/text/zh.json | 1 + 6 files changed, 281 insertions(+), 88 deletions(-) create mode 100644 e2e/fileTypesLayout.spec.ts diff --git a/e2e/fileTypesLayout.spec.ts b/e2e/fileTypesLayout.spec.ts new file mode 100644 index 000000000..76d438f19 --- /dev/null +++ b/e2e/fileTypesLayout.spec.ts @@ -0,0 +1,62 @@ +import { expect, stubDesktop, test } from "./fixtures"; + +test("File Types keeps association editors usable and opens ignored rules from search", async ({ workbench: page }) => { + await page.setViewportSize({ width: 1120, height: 760 }); + await page.keyboard.press("Meta+,"); + const settings = page.getByRole("dialog", { name: "Settings", exact: true }); + await expect(settings).toBeVisible(); + await stubDesktop(page); + await page.evaluate(() => { + window.__ipc.handlers.languages = () => [ + { id: "javascript", name: "JavaScript", extensions: ["js"] }, + { id: "python", name: "Python", extensions: ["py", "pyi", "pyw"], filenames: ["SConstruct", "SConscript"] }, + ]; + }); + const search = settings.getByRole("textbox", { name: "Search settings" }); + await search.fill("File Types"); + await settings.getByRole("treeitem", { name: "File Types", exact: true }).click(); + await search.clear(); + + const tabs = settings.getByRole("tablist", { name: "File Types" }); + const recognized = tabs.getByRole("tab", { name: "Recognized File Types" }); + const ignored = tabs.getByRole("tab", { name: "Ignored Files and Folders" }); + await expect(recognized).toHaveAttribute("aria-selected", "true"); + const divider = settings.getByRole("separator", { name: "Resize file type panes" }); + await expect(divider).toHaveAttribute("aria-orientation", "vertical"); + + await page.setViewportSize({ width: 520, height: 660 }); + await expect(divider).toHaveAttribute("aria-orientation", "horizontal"); + const types = settings.getByRole("listbox", { name: "Recognized file types", exact: true }); + await types.getByRole("option", { name: "Python", exact: true }).click(); + const patterns = settings.getByRole("listbox", { name: "File name patterns of Python" }); + const hashbangLabel = settings.getByText("Hashbang patterns", { exact: true }); + await expect + .poll(async () => { + const nameList = await patterns.boundingBox(); + const hashbangHeading = await hashbangLabel.boundingBox(); + return nameList && hashbangHeading ? hashbangHeading.y - (nameList.y + nameList.height) : -1; + }) + .toBeGreaterThan(0); + await expect + .poll(() => settings.locator("[class*='_patterns_']").evaluate((el) => el.scrollWidth - el.clientWidth)) + .toBeLessThanOrEqual(1); + const toolbar = settings.locator(`[role="toolbar"][aria-controls="${await patterns.getAttribute("id")}"]`); + await toolbar.getByRole("button", { name: "Add" }).click(); + const pattern = patterns.getByRole("textbox", { name: "Pattern" }); + await pattern.fill("*.layout-demo"); + await pattern.press("Enter"); + await expect(patterns.getByRole("option", { name: "*.layout-demo", exact: true })).toBeVisible(); + await expect + .poll(() => settings.locator("[class*='pageBody']").evaluate((el) => el.scrollWidth - el.clientWidth)) + .toBeLessThanOrEqual(1); + + await search.fill("Exclude patterns"); + await expect(ignored).toHaveAttribute("aria-selected", "true"); + await expect(settings.getByRole("listbox", { name: "Exclude patterns" })).toBeVisible(); + await expect(patterns).toBeHidden(); + await ignored.click(); + await search.clear(); + await ignored.press("ArrowLeft"); + await expect(recognized).toHaveAttribute("aria-selected", "true"); + await expect(patterns.getByRole("option", { name: "*.layout-demo", exact: true })).toBeVisible(); +}); diff --git a/src/features/settings/pages/FileTypes.module.css b/src/features/settings/pages/FileTypes.module.css index 3582f819c..5117893f3 100644 --- a/src/features/settings/pages/FileTypes.module.css +++ b/src/features/settings/pages/FileTypes.module.css @@ -1,25 +1,35 @@ +.tabs { + margin-bottom: var(--space-3); +} + .fileTypes { - display: grid; - grid-template-columns: minmax(180px, 260px) minmax(0, 1fr); - gap: var(--space-3); + container: file-types / inline-size; + height: clamp(382px, 67vh, 500px); min-width: 0; } +.split { + height: 100%; +} + .types { display: flex; flex-direction: column; gap: var(--space-1-5); - min-width: 0; + height: 100%; + padding-inline-end: var(--space-2); } .filter { + flex: none; width: 100%; } .typeList { display: flex; flex-direction: column; - max-height: 420px; + flex: 1; + min-height: 0; overflow: auto; padding: 2px 0; border-radius: var(--radius-small); @@ -27,11 +37,12 @@ } .type { + flex: none; display: flex; align-items: center; gap: var(--space-1-5); height: var(--h-row); - padding: 0 8px; + padding: 0 var(--space-2); border: none; background: none; color: var(--fg); @@ -65,6 +76,20 @@ flex-direction: column; gap: var(--space-1); min-width: 0; + height: 100%; + overflow: auto; + padding-inline-start: var(--space-3); +} + +.patterns > .patternRow { + flex: none; + margin-inline: 0; + padding-inline: 0; +} + +.patterns [role="listbox"] { + min-height: 72px; + max-height: 128px; } .note { @@ -74,10 +99,17 @@ .code { font-family: var(--font-mono); + overflow-wrap: anywhere; } -@media (max-width: 640px) { - .fileTypes { - grid-template-columns: minmax(0, 1fr); +@container file-types (width < 530px) { + .types { + padding-inline-end: 0; + padding-block-end: var(--space-2); + } + + .patterns { + padding-inline-start: 0; + padding-block-start: var(--space-2); } } diff --git a/src/features/settings/pages/FileTypes.tsx b/src/features/settings/pages/FileTypes.tsx index c0118a303..76ecb1783 100644 --- a/src/features/settings/pages/FileTypes.tsx +++ b/src/features/settings/pages/FileTypes.tsx @@ -4,9 +4,9 @@ * user's) and hashbang patterns, stored in `files.fileTypes`. The backend * detects languages with them; open editors re-detect when they change. */ -import { useEffect, useMemo, useState } from "react"; +import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react"; import clsx from "clsx"; -import { Icon, Input, T, fileIconName } from "@/ui"; +import { Icon, Input, SplitGroup, SplitHandle, SplitPanel, T, fileIconName } from "@/ui"; import { commands, isTauri, type LanguageInfo_Serialize as LanguageInfo } from "@/platform/ipc"; import { addPattern, @@ -52,6 +52,19 @@ export function applyPatternEdit( } export function RecognizedFileTypes() { + const desktop = isTauri(); + const container = useRef(null); + const [stacked, setStacked] = useState(true); + useLayoutEffect(() => { + const element = container.current; + if (!element) return; + const measure = () => setStacked(element.clientWidth < 530); + measure(); + if (typeof ResizeObserver === "undefined") return; + const observer = new ResizeObserver(measure); + observer.observe(element); + return () => observer.disconnect(); + }, [desktop]); const langs = useLanguages(); const [assoc, setAssoc] = useSetting("files.fileTypes"); const [filter, setFilter] = useState(""); @@ -68,74 +81,87 @@ export function RecognizedFileTypes() { }, [langs, filter, assoc]); // Keep the last explicit choice for when it becomes visible again. const selected = shown.find((l) => l.id === selectedId) ?? shown[0] ?? null; - if (!isTauri()) return null; + if (!desktop) return null; const current = assoc ?? {}; const patterns = selected ? effectivePatterns(selected, current).map((p) => p.pattern) : []; const hashbangs = selected ? (current[selected.id]?.hashbangs ?? []) : []; return ( -
-
- setFilter(e.target.value)} - /> -
- {shown.map((l) => { - const sample = sampleFileName(l); - return ( - + ); + })} +
+
+ + + + {selected && ( +
+ - - {l.name} - {current[l.id] && ( - - modified - - )} - - ); - })} -
-
- {selected && ( -
- - setAssoc(applyPatternEdit(current, langs, selected, next))} - placeholder="*.ext" - aria-label={tx`File name patterns of ${selected.name}`} - /> - - - setAssoc(setHashbangs(current, selected.id, next))} - placeholder="interpreter" - aria-label={tx`Hashbang patterns of ${selected.name}`} - /> - - {selected.firstLine && ( -
- Also recognized by its first line: {selected.firstLine} + setAssoc(applyPatternEdit(current, langs, selected, next))} + placeholder="*.ext" + aria-label={tx`File name patterns of ${selected.name}`} + /> + + + setAssoc(setHashbangs(current, selected.id, next))} + placeholder="interpreter" + aria-label={tx`Hashbang patterns of ${selected.name}`} + /> + + {selected.firstLine && ( +
+ Also recognized by its first line: {selected.firstLine} +
+ )}
)} -
- )} + + ); } diff --git a/src/features/settings/pages/builtins.tsx b/src/features/settings/pages/builtins.tsx index 0beb7ae23..b330c63be 100644 --- a/src/features/settings/pages/builtins.tsx +++ b/src/features/settings/pages/builtins.tsx @@ -1,9 +1,14 @@ /** Built-in settings pages (IDEA layout: Appearance & Behavior, Keymap, Editor). */ +import { useId, useState } from "react"; +import { Tabs } from "@/ui"; import { GlobListEditor, Row } from "../components/Form"; -import { useSetting } from "../components/context"; +import { useSearchQuery, useSetting } from "../components/context"; import { keymapSearchLabels } from "../keymap/model"; +import { labelMatches, queryTerms } from "../model/pages"; import { lazyPage } from "./lazyPage"; -import type { PageSpec } from "./spec"; +import { OptionsPage } from "./OptionsPage"; +import { specLabels, type PageSpec, type SectionSpec } from "./spec"; +import styles from "./FileTypes.module.css"; export const EDITOR_GROUP = "Editor"; const KeymapPage = lazyPage("keymap", () => import("../keymap/KeymapPage").then((m) => m.KeymapPage)); @@ -38,22 +43,10 @@ function IgnoredNamesRow() { ); } -export const BUILTIN_PAGES: PageSpec[] = [ +const FILE_TYPE_TABS: { id: string; label: string; sections: SectionSpec[] }[] = [ { - id: "keymap", - title: "Keymap", - order: 10, - keywords: ["shortcut", "keyboard", "hotkey", "binding", "preset", "vs code", "intellij"], - component: KeymapPage, - dynamicLabels: keymapSearchLabels, - }, - { - id: "editor.files", - title: "File Types", - group: EDITOR_GROUP, - order: 29, - projectScope: true, - keywords: ["ignore", "ignored", "excluded", "glob", "exclude patterns", "associate", "association", "extension"], + id: "recognized", + label: "Recognized File Types", sections: [ { title: "Recognized File Types", @@ -77,6 +70,12 @@ export const BUILTIN_PAGES: PageSpec[] = [ }, ], }, + ], + }, + { + id: "ignored", + label: "Ignored Files and Folders", + sections: [ { title: "Ignored Files and Folders", options: [ @@ -87,3 +86,75 @@ export const BUILTIN_PAGES: PageSpec[] = [ ], }, ]; + +const FILE_TYPES: PageSpec = { + id: "editor.files", + title: "File Types", + group: EDITOR_GROUP, + order: 29, + projectScope: true, + keywords: ["ignore", "ignored", "excluded", "glob", "exclude patterns", "associate", "association", "extension"], + sections: FILE_TYPE_TABS.flatMap((tab) => tab.sections), + component: FileTypesPage, +}; + +function FileTypesPage() { + const prefix = useId(); + const query = useSearchQuery(); + const [selection, select] = useState({ id: "recognized", query: "" }); + let active = selection.id; + if (query !== selection.query) { + const terms = queryTerms(query); + let best = 0; + for (const tab of FILE_TYPE_TABS) { + const labels = specLabels({ ...FILE_TYPES, keywords: [], sections: tab.sections }); + const score = terms.filter((term) => labels.some((label) => labelMatches(label, term))).length; + if (score > best) { + best = score; + active = tab.id; + } + } + } + return ( + <> + ({ id, label }))} + activeId={active} + panelIdPrefix={prefix} + onSelect={(id) => select({ id, query })} + /> + {FILE_TYPE_TABS.map(({ id, sections }) => ( + + ))} + + ); +} + +export const BUILTIN_PAGES: PageSpec[] = [ + { + id: "keymap", + title: "Keymap", + order: 10, + keywords: ["shortcut", "keyboard", "hotkey", "binding", "preset", "vs code", "intellij"], + component: KeymapPage, + dynamicLabels: keymapSearchLabels, + }, + FILE_TYPES, +]; diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index b22fbdf44..182346452 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -9,6 +9,7 @@ "Resize font preview": "Resize font preview", "Table actions": "Table actions", "Table pages": "Table pages", + "Resize file type panes": "Resize file type panes", "Problems actions": "Problems actions", "TODO actions": "TODO actions", "Same as the existing configuration '{existing}'": "Same as the existing configuration '{existing}'", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 2d271a7ea..4bc38b273 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -9,6 +9,7 @@ "Resize font preview": "调整字体预览大小", "Table actions": "表数据操作", "Table pages": "表数据分页", + "Resize file type panes": "调整文件类型窗格大小", "Problems actions": "问题操作", "Windows file and folder names cannot end with a period or space": "Windows 文件和文件夹名称不能以句点或空格结尾", "Use URL template": "使用 URL 模板",