diff --git a/e2e/moduleSourcesLayout.spec.ts b/e2e/moduleSourcesLayout.spec.ts new file mode 100644 index 000000000..ef0f848a8 --- /dev/null +++ b/e2e/moduleSourcesLayout.spec.ts @@ -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"]' }]); +}); diff --git a/src/features/settings/languages/ProjectStructurePage.tsx b/src/features/settings/languages/ProjectStructurePage.tsx index 5609dba37..e46ae4aa4 100644 --- a/src/features/settings/languages/ProjectStructurePage.tsx +++ b/src/features/settings/languages/ProjectStructurePage.tsx @@ -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("projectStructure.contentRoots"); const list = roots ?? []; const add = async () => { @@ -252,17 +252,22 @@ function ContentRoots({ root }: { root: string }) { setRoots([...list, picked]); }; return ( -
- + <> +
+ +
+ {root}
+ {children} {list.map((r) => (
+ {r} @@ -275,7 +280,7 @@ function ContentRoots({ root }: { root: string }) { />
))} -
+ ); } @@ -412,6 +417,19 @@ function ModuleSourcesTab({ moduleKey }: { moduleKey: string }) { const moduleRoot = root ? (moduleKey === "." ? root : `${root}/${moduleKey}`) : null; const [expanded, setExpanded] = useState>(() => new Set(moduleRoot ? [moduleRoot] : [])); const [selected, setSelected] = useState(null); + const container = useRef(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 ( -
-
-
- - Mark as: - - {ROLES.map((r) => ( - - ))} + 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 ( +
+
+ + {tx(r.title)}
-
- - 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)} - /> -
- {moduleKey === "." && } -
-
- {moduleKey === "." && } - {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 ( -
-
- - {r.title} -
- {list.length === 0 && ( -
- None -
- )} - {list.map((x) => { - const shown = x.path || name || "."; - return ( -
- - {shown} - {x.detectedFrom && ( - {tx`detected from ${x.detectedFrom}`} - )} - - setPs(markFolder(ps, x.path, null, detected))} - /> -
- ); - })} +
+ + {shown} + {x.detectedFrom && {tx`detected from ${x.detectedFrom}`}} + + setPs(markFolder(ps, x.path, null, detected))} + />
); })} - {unmarkedDetected.length > 0 && ( -
- {unmarkedDetected.length === 1 - ? tx("1 detected folder is unmarked.") - : tx`${unmarkedDetected.length} detected folders are unmarked.`}{" "} - -
- )} -
- - { - "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)." - } - -
+ ); + }); + + return ( +
+ + +
+ + Mark as: + + {ROLES.map((r) => ( + + ))} +
+
+ + 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)} + /> +
+ {moduleKey === "." && } +
+ + +
+ {moduleKey === "." ? {markedFolders} : markedFolders} + {unmarkedDetected.length > 0 && ( +
+ {unmarkedDetected.length === 1 + ? tx("1 detected folder is unmarked.") + : tx`${unmarkedDetected.length} detected folders are unmarked.`}{" "} + +
+ )} +
+ + { + "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)." + } + +
+
+
+
); } @@ -874,7 +896,7 @@ function ModulesSection() {
)} -
+
* { + 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);