mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-22 23:56:05 -10:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4ffb13049 | ||
|
|
afe9a0a181 |
No files matched your search
@@ -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();
|
||||
});
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<HTMLDivElement>(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<FileTypeAssociations>("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 (
|
||||
<div className={styles.fileTypes}>
|
||||
<div className={styles.types}>
|
||||
<Input
|
||||
className={styles.filter}
|
||||
value={filter}
|
||||
placeholder="Filter file types"
|
||||
aria-label="Filter file types"
|
||||
onChange={(e) => setFilter(e.target.value)}
|
||||
/>
|
||||
<div className={styles.typeList} role="listbox" aria-label={tx("Recognized file types")}>
|
||||
{shown.map((l) => {
|
||||
const sample = sampleFileName(l);
|
||||
return (
|
||||
<button
|
||||
key={l.id}
|
||||
type="button"
|
||||
role="option"
|
||||
aria-selected={l.id === selected?.id}
|
||||
className={clsx(styles.type, l.id === selected?.id && styles.typeSelected)}
|
||||
onClick={() => setSelectedId(l.id)}
|
||||
<div className={styles.fileTypes} ref={container}>
|
||||
<SplitGroup orientation={stacked ? "vertical" : "horizontal"} className={styles.split}>
|
||||
<SplitPanel defaultSize="34%" minSize={stacked ? "106px" : "148px"}>
|
||||
<div className={styles.types}>
|
||||
<Input
|
||||
className={styles.filter}
|
||||
value={filter}
|
||||
placeholder="Filter file types"
|
||||
aria-label="Filter file types"
|
||||
onChange={(e) => setFilter(e.target.value)}
|
||||
/>
|
||||
<div className={styles.typeList} role="listbox" aria-label={tx("Recognized file types")}>
|
||||
{shown.map((l) => {
|
||||
const sample = sampleFileName(l);
|
||||
return (
|
||||
<button
|
||||
key={l.id}
|
||||
type="button"
|
||||
role="option"
|
||||
aria-selected={l.id === selected?.id}
|
||||
className={clsx(styles.type, l.id === selected?.id && styles.typeSelected)}
|
||||
onClick={() => setSelectedId(l.id)}
|
||||
>
|
||||
<Icon name={sample ? fileIconName(sample) : "file-text"} size={16} />
|
||||
<span className={styles.typeName}>{l.name}</span>
|
||||
{current[l.id] && (
|
||||
<span className={styles.modified}>
|
||||
<T>modified</T>
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</SplitPanel>
|
||||
<SplitHandle aria-label={tx("Resize file type panes")} />
|
||||
<SplitPanel defaultSize="66%" minSize={stacked ? "196px" : "190px"}>
|
||||
{selected && (
|
||||
<div className={styles.patterns} key={selected.id}>
|
||||
<Row
|
||||
className={styles.patternRow}
|
||||
label="File name patterns"
|
||||
stacked
|
||||
hint="* matches any characters, ? one (e.g. *.foo, Jenkinsfile)."
|
||||
>
|
||||
<Icon name={sample ? fileIconName(sample) : "file-text"} size={16} />
|
||||
<span className={styles.typeName}>{l.name}</span>
|
||||
{current[l.id] && (
|
||||
<span className={styles.modified}>
|
||||
<T>modified</T>
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
{selected && (
|
||||
<div className={styles.patterns} key={selected.id}>
|
||||
<Row label="File name patterns" stacked hint="* matches any characters, ? one (e.g. *.foo, Jenkinsfile).">
|
||||
<GlobListEditor
|
||||
value={patterns}
|
||||
onChange={(next) => setAssoc(applyPatternEdit(current, langs, selected, next))}
|
||||
placeholder="*.ext"
|
||||
aria-label={tx`File name patterns of ${selected.name}`}
|
||||
/>
|
||||
</Row>
|
||||
<Row
|
||||
label="Hashbang patterns"
|
||||
stacked
|
||||
hint="Interpreters run by a #! first line, e.g. node for #!/usr/bin/env node."
|
||||
>
|
||||
<GlobListEditor
|
||||
value={hashbangs}
|
||||
onChange={(next) => setAssoc(setHashbangs(current, selected.id, next))}
|
||||
placeholder="interpreter"
|
||||
aria-label={tx`Hashbang patterns of ${selected.name}`}
|
||||
/>
|
||||
</Row>
|
||||
{selected.firstLine && (
|
||||
<div className={styles.note}>
|
||||
<T>Also recognized by its first line:</T> <code className={styles.code}>{selected.firstLine}</code>
|
||||
<GlobListEditor
|
||||
value={patterns}
|
||||
onChange={(next) => setAssoc(applyPatternEdit(current, langs, selected, next))}
|
||||
placeholder="*.ext"
|
||||
aria-label={tx`File name patterns of ${selected.name}`}
|
||||
/>
|
||||
</Row>
|
||||
<Row
|
||||
className={styles.patternRow}
|
||||
label="Hashbang patterns"
|
||||
stacked
|
||||
hint="Interpreters run by a #! first line, e.g. node for #!/usr/bin/env node."
|
||||
>
|
||||
<GlobListEditor
|
||||
value={hashbangs}
|
||||
onChange={(next) => setAssoc(setHashbangs(current, selected.id, next))}
|
||||
placeholder="interpreter"
|
||||
aria-label={tx`Hashbang patterns of ${selected.name}`}
|
||||
/>
|
||||
</Row>
|
||||
{selected.firstLine && (
|
||||
<div className={styles.note}>
|
||||
<T>Also recognized by its first line:</T> <code className={styles.code}>{selected.firstLine}</code>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</SplitPanel>
|
||||
</SplitGroup>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
<>
|
||||
<Tabs
|
||||
aria-label="File Types"
|
||||
variant="compact"
|
||||
layout="wrap"
|
||||
className={styles.tabs}
|
||||
items={FILE_TYPE_TABS.map(({ id, label }) => ({ id, label }))}
|
||||
activeId={active}
|
||||
panelIdPrefix={prefix}
|
||||
onSelect={(id) => select({ id, query })}
|
||||
/>
|
||||
{FILE_TYPE_TABS.map(({ id, sections }) => (
|
||||
<div
|
||||
key={id}
|
||||
role="tabpanel"
|
||||
id={`${prefix}-panel-${id}`}
|
||||
aria-labelledby={`${prefix}-tab-${id}`}
|
||||
hidden={id !== active}
|
||||
>
|
||||
<OptionsPage
|
||||
spec={{
|
||||
...FILE_TYPES,
|
||||
sections: sections.map((section, i) => (i === 0 ? { ...section, title: undefined } : section)),
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
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,
|
||||
];
|
||||
@@ -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}'",
|
||||
|
||||
@@ -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 模板",
|
||||
|
||||
Reference in new issue
Block a user