From 5563345a8f784bdf35e7132f1c49904ab0e06c6a Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sat, 21 Nov 2026 13:52:34 +0800 Subject: [PATCH] fix(debugger): fit the full value viewer to its popup (#4958) Size the debugger's full-value popup to the workbench and let the text fill the available space as the popup grows. Render the value with the configured editor font, line height and tab width. Keep the resized popup visible if the workbench shrinks. --- e2e/debugValueLayout.spec.ts | 86 +++++++++++++++++++ .../debugger/ui/VariablesView.module.css | 23 +++-- src/features/debugger/ui/VariablesView.tsx | 31 +++++-- src/ui/Dialog.tsx | 15 ++++ 4 files changed, 142 insertions(+), 13 deletions(-) create mode 100644 e2e/debugValueLayout.spec.ts diff --git a/e2e/debugValueLayout.spec.ts b/e2e/debugValueLayout.spec.ts new file mode 100644 index 0000000000..5af7783caf --- /dev/null +++ b/e2e/debugValueLayout.spec.ts @@ -0,0 +1,86 @@ +import { expect, stubDesktop, test } from "./fixtures"; + +test.use({ reducedMotion: "reduce" }); + +const NAME = "settlementTranscript"; +const TRANSCRIPT = Array.from( + { length: 78 }, + (_, index) => `Event ${String(index + 1).padStart(3, "0")}\tSettlement record verified`, +).join("\n"); + +test("the debugger's full value uses the editor font and fills the resized viewer", async ({ workbench: page }) => { + await page.setViewportSize({ width: 1320, height: 880 }); + await stubDesktop(page); + await page.evaluate( + async ({ name, transcript }) => { + const project = "/src/platform/project.ts"; + const debug = "/src/features/debugger/state.ts"; + const services = "/src/workbench/contributions.ts"; + const { useProject } = await import(/* @vite-ignore */ project); + const { settings } = useProject.getState(); + useProject.setState({ + settings: { ...settings, editor: { ...settings?.editor, fontSize: 18, lineHeight: 24, tabSize: 8 } }, + }); + const { adoptSession } = await import(/* @vite-ignore */ debug); + const { toolWindowService } = await import(/* @vite-ignore */ services); + const ipc = window.__ipc.handlers; + ipc.debug_scopes = () => [{ name: "Locals", variablesReference: 100, expensive: false }]; + ipc.debug_variables = () => [ + { + name, + value: JSON.stringify(transcript.slice(0, 720)), + typeName: "str", + variablesReference: 0, + evaluateName: name, + }, + ]; + ipc.debug_evaluate_in = () => ({ + name, + value: JSON.stringify(transcript), + typeName: "str", + variablesReference: 0, + evaluateName: name, + }); + adoptSession(91, { + name: "Settlement review", + adapter: "debugpy", + status: "paused", + selectedFrame: 11, + frames: [{ id: 11, name: "checkout", path: null, line: 0, column: 0, presentationHint: null }], + }); + toolWindowService().show("debug", true); + }, + { name: NAME, transcript: TRANSCRIPT }, + ); + const debug = page.getByRole("region", { name: "Debug", exact: true }); + await debug.getByRole("tab", { name: "Threads & Variables", exact: true }).click(); + await debug.getByRole("treeitem").filter({ hasText: NAME }).getByTitle("Show", { exact: true }).click(); + const dialog = page.getByRole("dialog", { name: `Value of ${NAME}` }); + const value = dialog.locator("pre"); + await expect(value).toHaveText(TRANSCRIPT, { useInnerText: false }); + await expect(value).toHaveCSS("font-size", "18px"); + await expect(value).toHaveCSS("line-height", "24px"); + await expect(value).toHaveCSS("tab-size", "8"); + await expect(value).toBeFocused(); + const before = (await value.boundingBox())!.height; + const grip = (await dialog.getByRole("separator", { name: "Resize", exact: true }).boundingBox())!; + const x = grip.x + grip.width - 3; + const y = grip.y + grip.height - 3; + await page.mouse.move(x, y); + await page.mouse.down(); + await page.mouse.move(x + 190, y + 180, { steps: 6 }); + await page.mouse.up(); + await expect.poll(async () => (await value.boundingBox())!.height).toBeGreaterThan(before + 120); + const overflow = (el: Element) => el.scrollHeight - el.clientHeight; + expect(await dialog.locator("[data-dialog-body]").evaluate(overflow)).toBe(0); + expect(await value.evaluate(overflow)).toBeGreaterThan(0); + + await page.setViewportSize({ width: 490, height: 440 }); + await expect(dialog).toBeInViewport({ ratio: 1 }); + await expect(value).toBeInViewport({ ratio: 1 }); + await value.evaluate((el) => (el.scrollTop = el.scrollHeight)); + expect(await value.evaluate((el) => el.scrollTop)).toBeGreaterThan(0); + expect(await value.textContent()).toBe(TRANSCRIPT); + await page.keyboard.press("Escape"); + await expect(dialog).toBeHidden(); +}); diff --git a/src/features/debugger/ui/VariablesView.module.css b/src/features/debugger/ui/VariablesView.module.css index 1c1438ab71..bf073dcf77 100644 --- a/src/features/debugger/ui/VariablesView.module.css +++ b/src/features/debugger/ui/VariablesView.module.css @@ -92,23 +92,32 @@ border-radius: var(--radius-small); } -.valuePopupContent { - padding: 12px 16px; +.valuePopup { + height: clamp(240px, 50vh, 560px); +} + +.valuePopup > [data-dialog-body] { + display: flex; + overflow: hidden; } .valuePopupValue { - max-height: min(420px, calc(100vh - 120px)); + flex: 1; + min-width: 0; margin: 0; + padding: var(--space-3) var(--space-4); overflow: auto; color: var(--fg); - font-family: var(--font-mono); - font-size: var(--fs-code); - font-weight: var(--fw-code); white-space: pre-wrap; - word-break: break-word; + overflow-wrap: anywhere; user-select: text; } +.valuePopupValue:focus-visible { + outline: 1px solid var(--focus-ring); + outline-offset: -1px; +} + .number { color: var(--syn-number); } diff --git a/src/features/debugger/ui/VariablesView.tsx b/src/features/debugger/ui/VariablesView.tsx index 6bf9c92d23..157fda34ef 100644 --- a/src/features/debugger/ui/VariablesView.tsx +++ b/src/features/debugger/ui/VariablesView.tsx @@ -5,6 +5,9 @@ import clsx from "clsx"; import { call, commands, type DebugSessionId, type Variable } from "@/platform/ipc"; import { Dialog, Icon, Tree, acquirePopup, showContextMenu, type MenuItem, type TreeHandle } from "@/ui"; import { formatMessage, tx } from "@/platform/i18n"; +import { fontWeightOf } from "@/platform/editorSettings"; +import { resolveMonoFont } from "@/platform/fonts"; +import { useProject } from "@/platform/project"; import { activeEditor } from "@/editor/api"; import { notifications } from "@/workbench/contributions"; import { addFieldWatchpoint } from "../breakpoints/special"; @@ -490,6 +493,8 @@ function ValueDialog({ onClose: () => void; }) { const [value, setValue] = useState(node.value); + const editor = useProject((s) => s.settings?.editor); + const { family, size } = resolveMonoFont(undefined, editor); useEffect(() => { const s = session != null ? useDebug.getState().sessions[session] : undefined; if (!s || s.status !== "paused" || !node.evaluateName || node.reference > 0) return; @@ -510,15 +515,29 @@ function ValueDialog({ dismissOnBackdrop onClose={onClose} title={`${node.name}${node.typeName ? ` {${node.typeName}}` : ""}`} - width={720} - minHeight={260} - maxHeight={560} + width="clamp(420px, 50vw, 820px)" + minWidth={320} + minHeight={200} resizable="both" aria-label={formatMessage(tx("Value of {label}"), { label: node.name })} + className={styles.valuePopup} > -
-
{text}
-
+
+        {text}
+      
); } diff --git a/src/ui/Dialog.tsx b/src/ui/Dialog.tsx index ee28620c78..f1cd6323f1 100644 --- a/src/ui/Dialog.tsx +++ b/src/ui/Dialog.tsx @@ -272,6 +272,21 @@ function DialogInner({ }; }, []); + useEffect(() => { + if (!popup || !resizable) return; + const fitPopup = () => { + const rect = ref.current?.getBoundingClientRect(); + if (!rect) return; + const left = Math.max(0, Math.min(rect.left, window.innerWidth - rect.width)); + const top = Math.max(0, Math.min(rect.top, window.innerHeight - rect.height)); + if (left !== rect.left || top !== rect.top) { + setOffset({ x: offset.x + left - rect.left, y: offset.y + top - rect.top }); + } + }; + window.addEventListener("resize", fitPopup); + return () => window.removeEventListener("resize", fitPopup); + }, [popup, resizable, offset]); + const cancelOnDeactivate = closeOnDeactivate ?? popup; useEffect(() => { if (!cancelOnDeactivate) return;