From bbedf7e1f658431357204dd7fdbda5885955279e Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Fri, 20 Nov 2026 08:26:21 +0800 Subject: [PATCH] Make Inspections panes fit narrow settings windows (#4629) Inspections settings panes resize and fit narrow settings windows. Verified with e2e inspectionsLayout/settingsFormLayout, full vitest and typecheck. --- e2e/inspectionsLayout.spec.ts | 52 +++++++ .../pages/editor/Inspections.module.css | 77 ++++++---- .../settings/pages/editor/InspectionsBody.tsx | 139 ++++++++++++------ src/platform/locales/text/en.json | 3 + src/platform/locales/text/zh.json | 3 + 5 files changed, 200 insertions(+), 74 deletions(-) create mode 100644 e2e/inspectionsLayout.spec.ts diff --git a/e2e/inspectionsLayout.spec.ts b/e2e/inspectionsLayout.spec.ts new file mode 100644 index 000000000..97161d799 --- /dev/null +++ b/e2e/inspectionsLayout.spec.ts @@ -0,0 +1,52 @@ +import { expect, test } from "./fixtures"; + +test("Inspections keeps the selected rule and its controls usable as the pane changes width", async ({ + workbench: page, +}) => { + await page.setViewportSize({ width: 620, height: 720 }); + await page.keyboard.press("Meta+,"); + const dialog = page.getByRole("dialog", { name: "Settings", exact: true }); + await expect(dialog).toBeVisible(); + await page.evaluate(async () => { + const path = "/src/features/settings/model/staging.ts"; + (await import(/* @vite-ignore */ path)).selectPage("editor.inspections"); + }); + + const search = dialog.getByRole("textbox", { name: "Search inspections" }); + await search.fill("typo"); + const tree = dialog.getByRole("tree", { name: "Inspections" }); + const typo = tree.getByRole("treeitem", { name: /Typo/ }); + await typo.click(); + const body = dialog.locator("[class*='pageBody']"); + await expect.poll(() => body.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1); + + const resize = dialog.getByRole("separator", { name: "Resize inspection panes" }); + const details = dialog.getByRole("region", { name: "Inspection details" }); + await expect(resize).toHaveAttribute("aria-orientation", "horizontal"); + await expect(details.getByRole("heading", { name: "Typo" })).toBeVisible(); + const narrowTree = await tree.boundingBox(); + const narrowDetails = await details.boundingBox(); + expect(narrowDetails!.y).toBeGreaterThan(narrowTree!.y + narrowTree!.height); + + await expect(details.getByRole("separator", { name: "Resize inspection description" })).toHaveAttribute( + "aria-orientation", + "horizontal", + ); + const severity = details.getByRole("button", { name: "Severity" }); + const severityBox = await severity.boundingBox(); + expect(severityBox!.y + severityBox!.height).toBeLessThan(narrowDetails!.y + narrowDetails!.height); + await severity.click(); + await page.getByRole("option", { name: "Warning", exact: true }).click(); + const code = details.getByRole("checkbox", { name: "Process code" }); + await code.uncheck(); + await expect(severity).toHaveText("Warning"); + + await page.setViewportSize({ width: 1040, height: 740 }); + await expect(resize).toHaveAttribute("aria-orientation", "vertical"); + const width = (await tree.boundingBox())!.width; + await resize.press("ArrowRight"); + await expect.poll(async () => (await tree.boundingBox())!.width).toBeGreaterThan(width + 5); + await expect(typo).toHaveAttribute("aria-selected", "true"); + await expect(severity).toHaveText("Warning"); + await expect(code).not.toBeChecked(); +}); diff --git a/src/features/settings/pages/editor/Inspections.module.css b/src/features/settings/pages/editor/Inspections.module.css index 9c9462b71..8619cd39b 100644 --- a/src/features/settings/pages/editor/Inspections.module.css +++ b/src/features/settings/pages/editor/Inspections.module.css @@ -2,21 +2,30 @@ display: flex; flex-direction: column; height: 100%; + min-width: 0; min-height: 420px; } .profileRow { display: flex; + flex-wrap: wrap; align-items: center; - gap: 10px; + gap: var(--space-1) var(--space-3); min-height: 30px; - margin-bottom: 8px; + margin-bottom: var(--space-2); } -.profileSelect { - min-width: 220px; +.profileControls { + display: flex; + align-items: center; + gap: var(--space-2); + max-width: 100%; + min-width: 0; } -.profileRow > span { +.profileControls > span { flex: none; - white-space: nowrap; +} +.profileControls > .profileSelect { + width: 220px; + min-width: 0; } .toolbar { display: flex; @@ -26,24 +35,19 @@ } .search { flex: 1; + min-width: 0; max-width: 320px; - margin-right: 4px; + margin-right: var(--space-1); } .split { flex: 1; - min-width: 520px; - min-height: 0; - display: flex; - gap: var(--space-3); + min-width: 0; } .treeWrap { - flex: 3; min-width: 0; - display: flex; - flex-direction: column; border-radius: var(--radius-small); box-shadow: inset 0 0 0 1px var(--border); - padding: 2px 0; + padding: var(--space-0-5) 0; } .empty { padding: 8px 12px; @@ -80,13 +84,20 @@ flex: none; } .details { - flex: 2; + flex: 1; min-width: 0; + min-height: 0; display: flex; flex-direction: column; - gap: 10px; - padding: 2px 4px; - overflow: auto; + gap: var(--space-2); + padding: var(--space-3); +} +.detailTitle { + margin: 0; + color: var(--fg-strong); + font-size: var(--fs-ui); + font-weight: 600; + overflow-wrap: anywhere; } .description { margin: 0; @@ -95,19 +106,34 @@ white-space: pre-wrap; overflow-wrap: anywhere; } -.severityRow { +.descriptionPane, +.optionsPane { + min-height: 0; + overflow: auto; +} +.descriptionPane { + padding-bottom: var(--space-2); +} +.optionsPane { display: flex; + flex-direction: column; + gap: var(--space-2); + padding-top: var(--space-2); +} +.severityRow { + flex: none; + display: flex; + flex-wrap: wrap; align-items: center; gap: var(--space-2); - padding-top: 10px; - border-top: 1px solid var(--border); } .options { + flex: none; display: flex; flex-direction: column; gap: var(--space-1-5); margin: 0; - padding: 10px 0 0; + padding: var(--space-2) 0 0; border: none; border-top: 1px solid var(--border); min-width: 0; @@ -115,11 +141,12 @@ .options legend { float: left; width: 100%; - padding: 0 0 4px; + padding: 0 0 var(--space-1); color: var(--fg-muted); } .levelSelect { - min-width: 160px; + width: 160px; + max-width: 100%; } .profileLevel { color: var(--fg-subtle); diff --git a/src/features/settings/pages/editor/InspectionsBody.tsx b/src/features/settings/pages/editor/InspectionsBody.tsx index e31615704..0b884f476 100644 --- a/src/features/settings/pages/editor/InspectionsBody.tsx +++ b/src/features/settings/pages/editor/InspectionsBody.tsx @@ -5,7 +5,7 @@ * chosen one is in effect for the project (editor highlighting, Problems, * Inspect Code). */ -import { useEffect, useId, useMemo, useRef, useState, type MouseEvent } from "react"; +import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState, type MouseEvent } from "react"; import clsx from "clsx"; import { BUILTIN_INSPECTIONS, @@ -34,6 +34,9 @@ import { Input, SearchField, Select, + SplitGroup, + SplitHandle, + SplitPanel, T, Tree, showContextMenu, @@ -92,6 +95,19 @@ function expandableKeys(nodes: readonly InspectionNode[], out = new Set( } export function InspectionsPage() { + const pageRef = useRef(null); + const [stacked, setStacked] = useState(false); + useLayoutEffect(() => { + const page = pageRef.current; + if (!page) return; + const measure = () => setStacked(page.clientWidth < 560); + measure(); + if (typeof ResizeObserver === "undefined") return; + const observer = new ResizeObserver(measure); + observer.observe(page); + return () => observer.disconnect(); + }, []); + const hasProject = useProject((s) => !!s.project); const newProjects = useSettingsDialog((s) => s.newProjects); const projectAvailable = hasProject && !newProjects; @@ -223,20 +239,22 @@ export function InspectionsPage() { }; return ( -
+
- - Profile: - - setChosen(v)} + disabled={profileOptions.length < 2} + /> + +
{location.level === "project" ? "Stored in Project" : "Stored in IDE"} @@ -265,8 +283,16 @@ export function InspectionsPage() { />
-
-
+ { // Space toggles the selected inspection, as in IDEA. @@ -309,9 +335,12 @@ export function InspectionsPage() {
} /> -
-
-
+ + + +
+ + {nameDialog && ( void; }) { - if (!node) { - return ( -
-

- Select an inspection to see its description and change its severity. -

-
- ); - } - const id = node.id; + const id = node?.id; + const description = ( +

+ {node?.description ?? "Select an inspection to see its description and change its severity."} +

+ ); return ( -
-

- {node.description} -

- {id && ( -
- - Severity: - - + onChange(setLevel(overrides, id, v === AS_REPORTED ? undefined : (v as InspectionLevel))) + } + /> +
+ +
+ + + ) : ( +
{description}
+ )} + ); } diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 817b038ad..6694d2454 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -1,4 +1,7 @@ { + "Inspection details": "Inspection details", + "Resize inspection panes": "Resize inspection panes", + "Resize inspection description": "Resize inspection description", "Table actions": "Table actions", "Table pages": "Table pages", "Problems actions": "Problems actions", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 3058e79ef..e48765c7d 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -1,4 +1,7 @@ { + "Inspection details": "检查详情", + "Resize inspection panes": "调整检查窗格大小", + "Resize inspection description": "调整检查说明窗格大小", "Table actions": "表数据操作", "Table pages": "表数据分页", "Problems actions": "问题操作",