mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
fix(settings): fit Module Sources to the available width (#4953)
Put the folder tree and marked roots in a resizable split in Project Structure › Modules › Sources. The panels stack when the available width is too small for a side-by-side layout. The summary shows populated root groups and uses the 13 px workbench font for folder paths.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
|
||||
|
||||
test("Module Sources fits in a narrow dialog and keeps marking folders after resizing", async ({ workbench: page }) => {
|
||||
await page.setViewportSize({ width: 1200, height: 820 });
|
||||
await stubDesktop(page);
|
||||
await page.evaluate(async () => {
|
||||
const project = "/src/platform/project.ts";
|
||||
const { useProject } = await import(/* @vite-ignore */ project);
|
||||
const root = useProject.getState().project!.root;
|
||||
const settings = { ...useProject.getState().settings, projectStructure: { sourceRoots: ["src"] } };
|
||||
useProject.setState({ settings });
|
||||
const handlers = window.__ipc.handlers;
|
||||
handlers.fs_read_dir = ({ path }) =>
|
||||
path === root ? ["src", "audit-fixtures"].map((name) => ({ name, path: `${root}/${name}`, kind: "dir" })) : [];
|
||||
handlers.settings_get_global = () => settings;
|
||||
handlers.settings_set = () => settings;
|
||||
const actions = "/src/platform/actions.ts";
|
||||
await (await import(/* @vite-ignore */ actions)).executeAction("file.projectStructure", "modules");
|
||||
});
|
||||
|
||||
const dialog = page.getByRole("dialog", { name: "Project Structure" });
|
||||
const tree = dialog.getByRole("tree", { name: "Content root" });
|
||||
const marked = dialog.getByRole("region", { name: "Marked folders" });
|
||||
const divider = dialog.getByRole("separator", { name: "Marked folders" });
|
||||
await expect(divider).toHaveAttribute("aria-orientation", "vertical");
|
||||
await expect(marked.getByText("Source Folders")).toBeVisible();
|
||||
await expect(marked.getByText("Test Source Folders")).toHaveCount(0);
|
||||
const width = (await tree.boundingBox())!.width;
|
||||
await divider.press("ArrowRight");
|
||||
await expect.poll(async () => (await tree.boundingBox())!.width).toBeGreaterThan(width + 4);
|
||||
|
||||
const folder = tree.getByRole("treeitem", { name: "audit-fixtures", exact: true });
|
||||
await folder.click();
|
||||
await page.setViewportSize({ width: 640, height: 720 });
|
||||
await expect(divider).toHaveAttribute("aria-orientation", "horizontal");
|
||||
await expect(folder).toHaveAttribute("aria-selected", "true");
|
||||
const content = dialog.locator("[class*='psDialogBody']");
|
||||
expect(await content.evaluate((element) => element.scrollWidth)).toBe(
|
||||
await content.evaluate((element) => element.clientWidth),
|
||||
);
|
||||
expect((await marked.boundingBox())!.y).toBeGreaterThan((await tree.boundingBox())!.y);
|
||||
await dialog.getByRole("toolbar", { name: "Mark as" }).getByRole("button", { name: "Tests", exact: true }).click();
|
||||
await expect(marked.getByText("Test Source Folders")).toBeVisible();
|
||||
await expect(marked.getByText("audit-fixtures", { exact: true })).toHaveCSS("font-size", "13px");
|
||||
await expect(marked.getByRole("button", { name: "Unmark audit-fixtures", exact: true })).toBeVisible();
|
||||
expect(await ipcCalls(page, "settings_set")).toEqual([]);
|
||||
|
||||
await dialog.getByRole("button", { name: "Apply", exact: true }).click();
|
||||
await expect
|
||||
.poll(() => ipcCalls(page, "settings_set"))
|
||||
.toMatchObject([{ key: "projectStructure.testRoots", value: '["audit-fixtures"]' }]);
|
||||
});
|
||||
@@ -3,7 +3,7 @@
|
||||
* IntelliJ IDEA-style Project Structure configuration across Project, Modules
|
||||
* (Sources, Paths, Dependencies), Libraries, Facets, Artifacts, and SDKs.
|
||||
*/
|
||||
import { useCallback, useEffect, useId, useMemo, useState } from "react";
|
||||
import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from "react";
|
||||
import clsx from "clsx";
|
||||
import { Channel } from "@tauri-apps/api/core";
|
||||
import {
|
||||
@@ -243,7 +243,7 @@ function useBuildModelData(root: string | null): BuildModel | null {
|
||||
}
|
||||
|
||||
/** "+ Add Content Root" and the content roots, the project folder first (IDEA's module Sources tab). */
|
||||
function ContentRoots({ root }: { root: string }) {
|
||||
function ContentRoots({ root, children }: { root: string; children: ReactNode }) {
|
||||
const [roots, setRoots] = useProjectSetting<string[] | undefined>("projectStructure.contentRoots");
|
||||
const list = roots ?? [];
|
||||
const add = async () => {
|
||||
@@ -252,17 +252,22 @@ function ContentRoots({ root }: { root: string }) {
|
||||
setRoots([...list, picked]);
|
||||
};
|
||||
return (
|
||||
<div className={styles.rootGroup}>
|
||||
<Button size="small" variant="ghost" icon="plus" onClick={() => void add()}>
|
||||
<T>Add Content Root</T>
|
||||
</Button>
|
||||
<>
|
||||
<div className={styles.contentRootToolbar}>
|
||||
<Button size="small" variant="ghost" icon="plus" onClick={() => void add()}>
|
||||
<T>Add Content Root</T>
|
||||
</Button>
|
||||
</div>
|
||||
<div className={clsx(styles.rootItem, styles.contentRoot)}>
|
||||
<Icon name="module" size={14} />
|
||||
<span className={styles.rootPath} title={root}>
|
||||
{root}
|
||||
</span>
|
||||
</div>
|
||||
{children}
|
||||
{list.map((r) => (
|
||||
<div key={r} className={clsx(styles.rootItem, styles.contentRoot)}>
|
||||
<Icon name="module" size={14} />
|
||||
<span className={styles.rootPath} title={r}>
|
||||
{r}
|
||||
</span>
|
||||
@@ -275,7 +280,7 @@ function ContentRoots({ root }: { root: string }) {
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -412,6 +417,19 @@ function ModuleSourcesTab({ moduleKey }: { moduleKey: string }) {
|
||||
const moduleRoot = root ? (moduleKey === "." ? root : `${root}/${moduleKey}`) : null;
|
||||
const [expanded, setExpanded] = useState<Set<string>>(() => new Set(moduleRoot ? [moduleRoot] : []));
|
||||
const [selected, setSelected] = useState<DirNode | null>(null);
|
||||
const container = useRef<HTMLDivElement>(null);
|
||||
const [stacked, setStacked] = useState(false);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const view = container.current;
|
||||
if (!view) return;
|
||||
const measure = () => setStacked(view.clientWidth < 420);
|
||||
measure();
|
||||
if (typeof ResizeObserver === "undefined") return;
|
||||
const observer = new ResizeObserver(measure);
|
||||
observer.observe(view);
|
||||
return () => observer.disconnect();
|
||||
}, [moduleRoot]);
|
||||
|
||||
const load = useCallback(
|
||||
async (node: DirNode) => {
|
||||
@@ -480,111 +498,115 @@ function ModuleSourcesTab({ moduleKey }: { moduleKey: string }) {
|
||||
const unmarkedDetected = unmarkedRoots(moduleDetected, ps);
|
||||
const restore = () => setPs(restoreDetected(ps, moduleDetected));
|
||||
|
||||
return (
|
||||
<div className={styles.structure}>
|
||||
<div className={styles.structureTree}>
|
||||
<div className={styles.markBar} role="toolbar" aria-label={tx("Mark as")}>
|
||||
<span>
|
||||
<T>Mark as:</T>
|
||||
</span>
|
||||
{ROLES.map((r) => (
|
||||
<button
|
||||
key={r.role}
|
||||
type="button"
|
||||
className={styles.markButton}
|
||||
aria-pressed={role === r.role}
|
||||
disabled={markable === null || (!markable && r.role === "excluded")}
|
||||
onClick={() => mark(r.role)}
|
||||
>
|
||||
<Icon name={folderIconName(r.kind)} size={14} />
|
||||
{r.label}
|
||||
</button>
|
||||
))}
|
||||
const markedFolders = ROLES.map((r) => {
|
||||
const list = roots.filter(
|
||||
(x) => x.kind === r.role && (moduleKey === "." || x.path === moduleKey || x.path.startsWith(moduleKey + "/")),
|
||||
);
|
||||
if (!list.length) return null;
|
||||
return (
|
||||
<div key={r.role} className={styles.rootGroup}>
|
||||
<div className={clsx(styles.rootTitle, r.cls)}>
|
||||
<Icon name={folderIconName(r.kind)} size={14} />
|
||||
{tx(r.title)}
|
||||
</div>
|
||||
<div className={styles.treeScroll}>
|
||||
<Tree<DirNode>
|
||||
aria-label="Content root"
|
||||
roots={treeRoots}
|
||||
getKey={(n) => n.path}
|
||||
getLabel={(n) => n.name}
|
||||
getChildren={(n) => children.get(n.path)}
|
||||
isExpandable={() => true}
|
||||
loadChildren={load}
|
||||
expanded={expanded}
|
||||
onExpandedChange={(set) => setExpanded(set)}
|
||||
multiSelect={false}
|
||||
selected={selected ? new Set([selected.path]) : new Set()}
|
||||
onSelectionChange={(_s, lead) => setSelected(lead)}
|
||||
getIcon={(n) => {
|
||||
if (n.rel === null) return n.contentRoot ? "module" : folderIconName("plain");
|
||||
const r = rootRole(roots, n.rel);
|
||||
if (!n.rel && !r) return "module";
|
||||
return folderIconName(r ? ROLES.find((x) => x.role === r)!.kind : "plain");
|
||||
}}
|
||||
getDetail={(n) => (n.rel === "" ? (root ?? undefined) : n.contentRoot ? n.path : undefined)}
|
||||
/>
|
||||
</div>
|
||||
{moduleKey === "." && <ExcludeFiles />}
|
||||
</div>
|
||||
<div className={styles.roots} aria-label={tx("Marked folders")}>
|
||||
{moduleKey === "." && <ContentRoots root={rootNode.path} />}
|
||||
{ROLES.map((r) => {
|
||||
const list = roots.filter(
|
||||
(x) =>
|
||||
x.kind === r.role && (moduleKey === "." || x.path === moduleKey || x.path.startsWith(moduleKey + "/")),
|
||||
);
|
||||
{list.map((x) => {
|
||||
const shown = x.path || name || ".";
|
||||
return (
|
||||
<div key={r.role} className={styles.rootGroup}>
|
||||
<div className={clsx(styles.rootTitle, r.cls)}>
|
||||
<Icon name={folderIconName(r.kind)} size={14} />
|
||||
{r.title}
|
||||
</div>
|
||||
{list.length === 0 && (
|
||||
<div className={clsx(styles.rootItem, styles.note)}>
|
||||
<T>None</T>
|
||||
</div>
|
||||
)}
|
||||
{list.map((x) => {
|
||||
const shown = x.path || name || ".";
|
||||
return (
|
||||
<div key={x.path} className={styles.rootItem}>
|
||||
<span className={styles.rootPath} title={x.path || root || undefined}>
|
||||
{shown}
|
||||
{x.detectedFrom && (
|
||||
<span className={styles.rootHint}> {tx`detected from ${x.detectedFrom}`}</span>
|
||||
)}
|
||||
</span>
|
||||
<IconButton
|
||||
icon="close"
|
||||
size="small"
|
||||
iconSize={12}
|
||||
title={tx`Unmark ${shown}`}
|
||||
onClick={() => setPs(markFolder(ps, x.path, null, detected))}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
<div key={x.path} className={styles.rootItem}>
|
||||
<span className={styles.rootPath} title={x.path || root || undefined}>
|
||||
{shown}
|
||||
{x.detectedFrom && <span className={styles.rootHint}> {tx`detected from ${x.detectedFrom}`}</span>}
|
||||
</span>
|
||||
<IconButton
|
||||
icon="close"
|
||||
size="small"
|
||||
iconSize={12}
|
||||
title={tx`Unmark ${shown}`}
|
||||
onClick={() => setPs(markFolder(ps, x.path, null, detected))}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{unmarkedDetected.length > 0 && (
|
||||
<div className={styles.note}>
|
||||
{unmarkedDetected.length === 1
|
||||
? tx("1 detected folder is unmarked.")
|
||||
: tx`${unmarkedDetected.length} detected folders are unmarked.`}{" "}
|
||||
<button type="button" className={styles.linkButton} onClick={restore}>
|
||||
<T>Restore detected roots</T>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<div className={styles.note}>
|
||||
<T>
|
||||
{
|
||||
"Folders are detected from build files (pom.xml, build.gradle, Cargo.toml, go.mod, pyproject.toml, package.json, composer.json); marking or unmarking a folder overrides detection. Excluded folders are skipped by the Project view, Find in Files and the index (reopen the project to re-index)."
|
||||
}
|
||||
</T>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
return (
|
||||
<div ref={container} className={clsx(styles.structure, stacked && styles.structureStacked)}>
|
||||
<SplitGroup key={stacked ? "stacked" : "side-by-side"} orientation={stacked ? "vertical" : "horizontal"}>
|
||||
<SplitPanel
|
||||
id="module-source-tree"
|
||||
minSize={stacked ? 212 : 190}
|
||||
defaultSize={stacked ? "52%" : "60%"}
|
||||
className={styles.structureTree}
|
||||
>
|
||||
<div className={styles.markBar} role="toolbar" aria-label={tx("Mark as")}>
|
||||
<span>
|
||||
<T>Mark as:</T>
|
||||
</span>
|
||||
{ROLES.map((r) => (
|
||||
<button
|
||||
key={r.role}
|
||||
type="button"
|
||||
className={styles.markButton}
|
||||
aria-pressed={role === r.role}
|
||||
disabled={markable === null || (!markable && r.role === "excluded")}
|
||||
onClick={() => mark(r.role)}
|
||||
>
|
||||
<Icon name={folderIconName(r.kind)} size={14} />
|
||||
{tx(r.label)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className={styles.treeScroll}>
|
||||
<Tree<DirNode>
|
||||
aria-label="Content root"
|
||||
roots={treeRoots}
|
||||
getKey={(n) => n.path}
|
||||
getLabel={(n) => n.name}
|
||||
getChildren={(n) => children.get(n.path)}
|
||||
isExpandable={() => true}
|
||||
loadChildren={load}
|
||||
expanded={expanded}
|
||||
onExpandedChange={(set) => setExpanded(set)}
|
||||
multiSelect={false}
|
||||
selected={selected ? new Set([selected.path]) : new Set()}
|
||||
onSelectionChange={(_s, lead) => setSelected(lead)}
|
||||
getIcon={(n) => {
|
||||
if (n.rel === null) return n.contentRoot ? "module" : folderIconName("plain");
|
||||
const r = rootRole(roots, n.rel);
|
||||
if (!n.rel && !r) return "module";
|
||||
return folderIconName(r ? ROLES.find((x) => x.role === r)!.kind : "plain");
|
||||
}}
|
||||
getDetail={(n) => (n.rel === "" ? (root ?? undefined) : n.contentRoot ? n.path : undefined)}
|
||||
/>
|
||||
</div>
|
||||
{moduleKey === "." && <ExcludeFiles />}
|
||||
</SplitPanel>
|
||||
<SplitHandle aria-label={tx("Marked folders")} />
|
||||
<SplitPanel id="module-marked-folders" minSize={stacked ? 160 : 175}>
|
||||
<section className={styles.roots} aria-label={tx("Marked folders")}>
|
||||
{moduleKey === "." ? <ContentRoots root={rootNode.path}>{markedFolders}</ContentRoots> : markedFolders}
|
||||
{unmarkedDetected.length > 0 && (
|
||||
<div className={styles.note}>
|
||||
{unmarkedDetected.length === 1
|
||||
? tx("1 detected folder is unmarked.")
|
||||
: tx`${unmarkedDetected.length} detected folders are unmarked.`}{" "}
|
||||
<button type="button" className={styles.linkButton} onClick={restore}>
|
||||
<T>Restore detected roots</T>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<div className={styles.note}>
|
||||
<T>
|
||||
{
|
||||
"Folders are detected from build files (pom.xml, build.gradle, Cargo.toml, go.mod, pyproject.toml, package.json, composer.json); marking or unmarking a folder overrides detection. Excluded folders are skipped by the Project view, Find in Files and the index (reopen the project to re-index)."
|
||||
}
|
||||
</T>
|
||||
</div>
|
||||
</section>
|
||||
</SplitPanel>
|
||||
</SplitGroup>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -874,7 +896,7 @@ function ModulesSection() {
|
||||
</T>
|
||||
</div>
|
||||
)}
|
||||
<div className={styles.splitLayout}>
|
||||
<div className={clsx(styles.splitLayout, styles.modulesLayout)}>
|
||||
<div className={styles.sideList}>
|
||||
<div className={styles.tableToolbar}>
|
||||
<IconButton
|
||||
|
||||
@@ -303,18 +303,19 @@
|
||||
|
||||
/* Project Structure */
|
||||
.structure {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(240px, 1fr) 220px;
|
||||
gap: 10px;
|
||||
min-height: 420px;
|
||||
height: clamp(380px, 55vh, 520px);
|
||||
border-radius: var(--radius-small);
|
||||
box-shadow: inset 0 0 0 1px var(--border);
|
||||
}
|
||||
.structureStacked {
|
||||
height: clamp(440px, calc(100vh - 240px), 560px);
|
||||
}
|
||||
.structureTree {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
border-radius: var(--radius-small);
|
||||
box-shadow: inset 0 0 0 1px var(--border);
|
||||
overflow: hidden;
|
||||
container-type: inline-size;
|
||||
}
|
||||
.markBar {
|
||||
display: flex;
|
||||
@@ -350,6 +351,7 @@
|
||||
color: var(--fg-faint);
|
||||
}
|
||||
.treeScroll {
|
||||
--tree-detail-flex-shrink: 4;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
@@ -358,7 +360,13 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-3);
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
padding: var(--space-2);
|
||||
}
|
||||
.roots > * {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.rootGroup {
|
||||
display: flex;
|
||||
@@ -406,10 +414,9 @@
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1);
|
||||
padding-left: 20px;
|
||||
padding-inline-start: calc(var(--space-4) + var(--space-1));
|
||||
min-height: 22px;
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-small);
|
||||
font-size: var(--fs-ui);
|
||||
}
|
||||
.rootPath {
|
||||
flex: 1;
|
||||
@@ -428,9 +435,14 @@
|
||||
|
||||
/* Project Structure: content roots and "Exclude files". */
|
||||
.contentRoot {
|
||||
padding-left: 4px;
|
||||
padding-inline-start: var(--space-1);
|
||||
font-weight: 600;
|
||||
}
|
||||
.contentRootToolbar {
|
||||
display: flex;
|
||||
border-bottom: 1px solid var(--border);
|
||||
padding-bottom: var(--space-1);
|
||||
}
|
||||
.excludeFiles {
|
||||
display: grid;
|
||||
grid-template-columns: auto minmax(0, 1fr);
|
||||
@@ -448,6 +460,14 @@
|
||||
color: var(--fg-subtle);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
@container (max-width: 280px) {
|
||||
.excludeFiles {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
.excludeHint {
|
||||
grid-column: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Download JDK dialog */
|
||||
.downloadGrid {
|
||||
@@ -486,6 +506,21 @@
|
||||
color: var(--fg);
|
||||
font-weight: 500;
|
||||
}
|
||||
.splitLayout.modulesLayout {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
min-height: 0;
|
||||
}
|
||||
.modulesLayout > .sideList {
|
||||
flex: 1 1 140px;
|
||||
min-width: 0;
|
||||
}
|
||||
.modulesLayout > .detailPane {
|
||||
flex: 4 1 370px;
|
||||
}
|
||||
.modulesLayout .sideItems {
|
||||
max-height: min(360px, 42vh);
|
||||
}
|
||||
.splitLayout {
|
||||
display: grid;
|
||||
grid-template-columns: 268px minmax(300px, 1fr);
|
||||
|
||||
Reference in New Issue
Block a user