diff --git a/e2e/problems-layout.spec.ts b/e2e/problems-layout.spec.ts index e8b14b4ba0..f9068cdfda 100644 --- a/e2e/problems-layout.spec.ts +++ b/e2e/problems-layout.spec.ts @@ -1,4 +1,4 @@ -import { expect, test } from "./fixtures"; +import { expect, openFromTree, test } from "./fixtures"; test("keeps diagnostic text and file counts visible in a narrow Problems pane", async ({ workbench: page }) => { await page.setViewportSize({ width: 720, height: 760 }); @@ -32,3 +32,73 @@ test("keeps diagnostic text and file counts visible in a narrow Problems pane", await expect.poll(() => message.evaluate((element) => element.scrollWidth <= element.clientWidth)).toBe(true); await expect.poll(() => tree.evaluate((element) => element.scrollWidth <= element.clientWidth)).toBe(true); }); + +test("Problems stacks the preview in a side dock and remembers both divider positions", async ({ workbench: page }) => { + await page.setViewportSize({ width: 900, height: 700 }); + await openFromTree(page, "build.gradle.kts"); + await page.evaluate(async () => { + const projectModule = "/src/platform/project.ts"; + const problemsModule = "/src/features/code-insight/problemsStore.ts"; + const { useProject } = await import(/* @vite-ignore */ projectModule); + const { applyDiagnosticsEvent } = await import(/* @vite-ignore */ problemsModule); + const path = `${useProject.getState().project.root}/build.gradle.kts`; + applyDiagnosticsEvent(path, "kotlin", [ + { + range: { start: { line: 1, col: 2 }, end: { line: 1, col: 8 } }, + severity: "error", + source: "kotlin", + message: "Invalid plugin configuration", + }, + ]); + }); + const move = (anchor: "right" | "bottom") => + page.evaluate(async (anchor) => { + const path = "/src/workbench/toolwindows/store.ts"; + const { moveToolWindow, setToolWindowSize, showToolWindow } = await import(/* @vite-ignore */ path); + moveToolWindow("problems", anchor); + setToolWindowSize(anchor, 280); + showToolWindow("problems", true); + }, anchor); + await move("right"); + + const pane = page.getByRole("region", { name: "Problems", exact: true }); + const toolbar = pane.getByRole("toolbar", { name: "Problems actions" }); + const tree = pane.getByRole("tree", { name: "Problems" }); + const diagnostic = tree.getByRole("treeitem", { name: /Invalid plugin configuration/ }); + await pane.getByRole("button", { name: "Options", exact: true }).click(); + await page.getByRole("menuitemcheckbox", { name: "Show Preview", exact: true }).click(); + await diagnostic.click(); + const preview = pane.getByRole("region", { name: "Preview", exact: true }); + await expect(toolbar).toHaveAttribute("aria-orientation", "horizontal"); + await expect(preview).toContainText("class OrderController"); + + const box = (await tree.boundingBox())!; + const code = (await preview.boundingBox())!; + expect(code.y).toBeGreaterThanOrEqual(box.y + box.height - 1); + expect(Math.abs(code.width - box.width)).toBeLessThan(2); + expect((await toolbar.boundingBox())!.y).toBeLessThan(box.y); + + const handle = pane.getByRole("separator"); + const size = async () => Number(await handle.getAttribute("aria-valuenow")); + const resize = async (key: string) => { + const previous = await size(); + await handle.press(key); + await expect.poll(size).not.toBe(previous); + return size(); + }; + const sideSize = await resize("ArrowDown"); + await move("bottom"); + await expect(toolbar).toHaveAttribute("aria-orientation", "vertical"); + await expect.poll(size).toBeCloseTo(50, 0); + await diagnostic.click(); + await expect(preview).toContainText("class OrderController"); + const bottomTree = (await tree.boundingBox())!; + const bottomCode = (await preview.boundingBox())!; + expect(bottomCode.x).toBeGreaterThanOrEqual(bottomTree.x + bottomTree.width - 1); + const bottomSize = await resize("ArrowLeft"); + + await move("right"); + await expect.poll(size).toBeCloseTo(sideSize, 0); + await move("bottom"); + await expect.poll(size).toBeCloseTo(bottomSize, 0); +}); diff --git a/src/features/code-insight/ProblemsView.module.css b/src/features/code-insight/ProblemsView.module.css index 4cd7316a9d..002ea64ba6 100644 --- a/src/features/code-insight/ProblemsView.module.css +++ b/src/features/code-insight/ProblemsView.module.css @@ -19,6 +19,9 @@ min-height: 0; height: 100%; } +.resultsStacked { + flex-direction: column; +} .toolbar { flex: none; display: flex; @@ -28,6 +31,13 @@ border-inline-end: 1px solid var(--border); overflow-y: auto; } +.resultsStacked .toolbar { + flex-direction: row; + flex-wrap: wrap; + border-inline-end: 0; + border-block-end: 1px solid var(--border); + overflow: visible; +} .tree { flex: 1; min-width: 0; diff --git a/src/features/code-insight/ProblemsView.tsx b/src/features/code-insight/ProblemsView.tsx index 054daf2326..5394b8313c 100644 --- a/src/features/code-insight/ProblemsView.tsx +++ b/src/features/code-insight/ProblemsView.tsx @@ -13,6 +13,7 @@ import { basename, relativeDir, useProject } from "@/platform/project"; import { diagnosticInspection, producerOf, type InspectionRef } from "@/platform/inspections"; import { problemControls } from "@/platform/inspectionControls"; import { editorService, maybeEditorService, useOccurrenceNavigator } from "@/workbench/contributions"; +import { useToolWindowLayout } from "@/workbench/toolwindows/store"; import { EmptyState, Icon, @@ -72,7 +73,7 @@ const OPTIONS_KEY = "openidea.problems.view.v1"; interface ProblemsOptions extends ProblemOrder { /** Selecting a problem opens it in the editor. */ autoscroll: boolean; - /** Source preview beside the list. */ + /** Source preview in the Problems tool window. */ preview: boolean; } @@ -214,11 +215,11 @@ function useCurrentPath(): string | null { return currentProblemsPath(text, useSyncExternalStore(subscribeActiveInput, activeInput)); } -function ProblemsToolbar() { +function ProblemsToolbar({ orientation }: { orientation: "horizontal" | "vertical" }) { const show = useProblemsView((s) => s.show); const toggle = useProblemsView((s) => s.toggle); return ( - + toggle("error")} /> @@ -281,12 +282,16 @@ export function ProblemsTabs() { ); } +const DEFAULT_PREVIEW_LAYOUT = { problems: 50, preview: 50 }; + export function ProblemsView() { const map = useProblems((s) => s.map); const { tab, show } = useProblemsView(); const options = useProblemsOptions(); const current = useCurrentPath(); const root = useProject((s) => s.project?.root ?? ""); + const sideDocked = useToolWindowLayout((s) => (s.placements.problems?.anchor ?? "bottom") !== "bottom"); + const previewMinimum = sideDocked ? "25%" : 120; const [collapsed, setCollapsed] = useState>(() => new Set()); const [lead, setLead] = useState(null); const tree = useRef(null); @@ -454,8 +459,8 @@ export function ProblemsView() { /> ); const list = ( -
- +
+ {treeView}
); @@ -464,12 +469,17 @@ export function ProblemsView() {
{options.preview ? ( - - + + {list} - +