diff --git a/e2e/debug.spec.ts b/e2e/debug.spec.ts index 1af77663b..3f909588d 100644 --- a/e2e/debug.spec.ts +++ b/e2e/debug.spec.ts @@ -113,3 +113,60 @@ test("stops at a breakpoint, shows frames and variables, steps and resumes", asy await expect.poll(() => ipcCalls(page, "debug_resume")).toHaveLength(1); await expect(debug.getByText("CreateOrderRequest(sku='A-1', qty=2)")).toBeHidden(); }); + +test("Evaluate keeps a multiline expression and its result visible in a short dialog", async ({ workbench: page }) => { + await page.setViewportSize({ width: 580, height: 420 }); + await stubDesktop(page); + await page.evaluate(async (session) => { + const handlers = window.__ipc.handlers; + handlers.debug_capabilities = () => ({}); + handlers.debug_completions = () => []; + handlers.debug_evaluate_in = () => ({ + name: "orderSummary", + typeName: "OrderSummary", + value: "total = 36", + variablesReference: 210, + evaluateName: null, + }); + handlers.debug_variables = () => [ + { name: "tax", value: "4", typeName: "int", variablesReference: 0, evaluateName: null }, + ]; + const stateModule = "/src/features/debugger/state.ts"; + const { adoptSession } = await import(/* @vite-ignore */ stateModule); + adoptSession(session, { name: "Checkout", adapter: "debugpy", status: "paused", selectedFrame: 11 }); + }, SESSION); + + await page.keyboard.press("Alt+F8"); + const dialog = page.getByRole("dialog", { name: "Evaluate expression" }); + const field = dialog.getByRole("textbox", { name: "Expression" }); + const expression = ["orderSummary(", ...Array.from({ length: 12 }, (_, i) => ` item${i},`), ")"].join("\n"); + await field.fill(expression); + await field.press("Enter"); + const result = dialog.getByRole("tree", { name: "Evaluation result" }); + const row = result.getByRole("treeitem").first(); + await expect(row).toContainText("total = 36"); + await expect + .poll(() => + dialog.locator("[data-dialog-body]").evaluate((body) => { + const area = body.querySelector("textarea")!; + const resultRow = body.querySelector('[role="treeitem"]')!.getBoundingClientRect(); + const bounds = body.getBoundingClientRect(); + return ( + body.scrollHeight <= body.clientHeight + 1 && + area.scrollHeight > area.clientHeight && + resultRow.top >= bounds.top && + resultRow.bottom <= bounds.bottom + ); + }), + ) + .toBe(true); + await row.click(); + await row.press("ArrowRight"); + await expect(result.getByText("tax", { exact: true })).toBeVisible(); + + await field.fill("otherExpression"); + await dialog.getByRole("button", { name: "History", exact: true }).click(); + await page.getByRole("menuitem", { name: /orderSummary/ }).click(); + await expect(field).toHaveValue(expression); + await expect(field).toBeFocused(); +}); diff --git a/src/features/debugger/ui/Overlays.module.css b/src/features/debugger/ui/Overlays.module.css index 88aef79ab..cae3559e5 100644 --- a/src/features/debugger/ui/Overlays.module.css +++ b/src/features/debugger/ui/Overlays.module.css @@ -172,31 +172,72 @@ } /* evaluate dialog */ +.evalDialog { + height: min(440px, 100%); +} + .evalBody { height: 100%; - box-sizing: border-box; - padding: 12px 14px; + padding: var(--space-2) var(--space-3) 0; display: flex; flex-direction: column; - gap: 10px; + gap: var(--space-2); +} + +.evalExpression, +.evalResult { + display: flex; + flex-direction: column; + min-height: 0; + gap: var(--space-1); +} + +/* Long fragments scroll inside the field so the result keeps its own space. */ +.evalExpression { + max-height: 50%; } .evalImport { + flex: none; + max-height: 40%; + overflow: auto; + padding: var(--space-1); display: flex; flex-wrap: wrap; align-items: center; + align-content: start; gap: var(--space-1) var(--space-2); + border-bottom: 1px solid var(--border); +} + +.evalImport > button { + max-width: 100%; + height: auto; + min-height: var(--h-control); + white-space: normal; + overflow-wrap: anywhere; } -/* Grows with the dialog when it is resized. */ .evalResult { flex: 1; - min-height: 220px; +} + +.evalResultContent { + flex: 1; + min-height: 0; display: flex; flex-direction: column; border: 1px solid var(--border-popup); border-radius: var(--radius-small); - padding: 4px 6px; + padding: var(--space-0-5) var(--space-1); + overflow: hidden; +} + +.evalHint { + padding: var(--space-2); + color: var(--fg-muted); + font-size: var(--fs-small); + overflow: auto; } .chooser { @@ -259,33 +300,38 @@ /* Evaluate: a field that grows with ⇧Enter, like IDEA's expression editor. */ .evalInputRow { display: flex; - align-items: flex-start; - gap: var(--space-1); -} -.evalInput { - flex: 1; - min-width: 0; - min-height: var(--h-field, 28px); - padding: 5px 8px; - resize: none; - appearance: none; - border: 0; + min-height: 0; border-radius: var(--radius-control, 4px); background: var(--bg-field, var(--bg-button)); box-shadow: inset 0 0 0 1px var(--border-button); - color: var(--fg-strong); - font-family: var(--font-mono); - font-size: var(--fs-ui); - line-height: 18px; - outline: none; - -webkit-user-select: text; - user-select: text; } -.evalInput:focus { +.evalInputRow:focus-within { box-shadow: inset 0 0 0 1px var(--focus-ring), 0 0 0 1px var(--focus-ring); } +.evalInput { + flex: 1; + min-width: 0; + min-height: 0; + padding: var(--space-1) var(--space-2); + resize: none; + appearance: none; + border: 0; + background: none; + color: var(--fg-strong); + font-family: var(--font-mono); + font-size: var(--fs-code); + font-weight: var(--fw-code); + line-height: var(--lh-code); + outline: none; + -webkit-user-select: text; + user-select: text; +} .evalInput::placeholder { color: var(--fg-faint); } +.evalHistory { + align-self: flex-start; + margin: var(--space-1); +} diff --git a/src/features/debugger/ui/Overlays.tsx b/src/features/debugger/ui/Overlays.tsx index 8408d899a..eef942f23 100644 --- a/src/features/debugger/ui/Overlays.tsx +++ b/src/features/debugger/ui/Overlays.tsx @@ -764,8 +764,9 @@ function EvaluateDialogInner({ initial }: { initial: string }) { const [history, setHistory] = useState(() => readHistory("evaluate")); const [historyMenu, setHistoryMenu] = useState(false); const historyPos = useRef(-1); - const historyButton = useRef(null); + const historyButton = useRef(null); const field = useRef(null); + const expressionId = useId(); const session = useDebug((s) => (s.active != null ? s.sessions[s.active] : undefined)); const paused = session?.status === "paused"; const close = () => useOverlays.setState({ evaluate: null }); @@ -824,7 +825,10 @@ function EvaluateDialogInner({ initial }: { initial: string }) { onClose={close} title="Evaluate" width={620} + minWidth={340} + minHeight={240} resizable="both" + className={styles.evalDialog} aria-label="Evaluate expression" footerStart={