From aec1382e794e99499cd58dcebd8024eba4291dc6 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Mon, 23 Nov 2026 22:02:22 +0800 Subject: [PATCH] fix(agents): keep the prompt box free of scrollbars until it reaches its height limit (#5472) After one exchange, a new session's empty prompt box showed a horizontal scrollbar and a vertical thumb (visible with always-on scrollbars): the CodeMirror scroller kept a fixed height slightly taller than its content and allowed horizontal overflow. The scroller now sizes to its wrapped text, never scrolls horizontally, and scrolls vertically only past its 280 px limit. --- e2e/agentDraftSubmission.spec.ts | 57 +++++++++++++++++++++++++ src/features/agents/Composer.module.css | 2 + 2 files changed, 59 insertions(+) diff --git a/e2e/agentDraftSubmission.spec.ts b/e2e/agentDraftSubmission.spec.ts index 9ef35920b..0e14859f7 100644 --- a/e2e/agentDraftSubmission.spec.ts +++ b/e2e/agentDraftSubmission.spec.ts @@ -131,3 +131,60 @@ for (const home of [false, true]) { } } } + +test("short prompts fit before and after a completed agent exchange", async ({ workbench: page }) => { + await prepare(page, true, false); + const box = page.getByRole("textbox", { name: "Message", exact: true }).filter({ visible: true }); + const scroller = page.locator(".cm-scroller").filter({ has: box }); + const overflow = () => + scroller.evaluate((el) => ({ + x: el.scrollWidth - el.clientWidth, + y: el.scrollHeight - el.clientHeight, + })); + + await expect(box.locator(".cm-placeholder")).toBeVisible(); + await expect.poll(overflow).toEqual({ x: 0, y: 0 }); + await box.fill("Reply with OK."); + await expect.poll(overflow).toEqual({ x: 0, y: 0 }); + await page.getByRole("button", { name: "Start", exact: true }).click(); + await expect(page.locator("html")).toHaveAttribute("data-submitted-prompt", /Reply with OK/); + await page.evaluate(() => document.dispatchEvent(new Event("test:agent-ack"))); + await expect(page.getByRole("tab", { name: task.title })).toBeVisible(); + await page.evaluate(async (id) => { + const storePath = "/src/features/agents/store.ts"; + const { useAgents } = await import(storePath); + useAgents.setState({ + entries: new Map([ + [ + id, + [ + { type: "user", text: "Reply with OK.", attachments: [] }, + { type: "agent", text: "OK" }, + ], + ], + ]), + }); + }, task.id); + await expect(page.getByText("OK", { exact: true })).toBeVisible(); + await expect.poll(overflow).toEqual({ x: 0, y: 0 }); + + await page.getByRole("button", { name: "Agents", exact: true }).click(); + await page.getByRole("button", { name: "New Agent Task", exact: true }).click(); + await expect(box.locator(".cm-placeholder")).toBeVisible(); + await expect(scroller).toHaveCSS("overflow-x", "hidden"); + await expect.poll(overflow).toEqual({ x: 0, y: 0 }); + await box.fill("Short draft"); + await expect.poll(overflow).toEqual({ x: 0, y: 0 }); + + await box.fill("word".repeat(2000)); + await expect(scroller).toHaveCSS("overflow-y", "auto"); + await expect + .poll(async () => { + const { x, y } = await overflow(); + return x === 0 && y > 0; + }) + .toBe(true); + await box.fill(""); + await expect(box.locator(".cm-placeholder")).toBeVisible(); + await expect.poll(overflow).toEqual({ x: 0, y: 0 }); +}); diff --git a/src/features/agents/Composer.module.css b/src/features/agents/Composer.module.css index 46e9d557d..19b82886e 100644 --- a/src/features/agents/Composer.module.css +++ b/src/features/agents/Composer.module.css @@ -36,7 +36,9 @@ outline: none; } .field :global(.cm-scroller) { + height: auto; max-height: 280px; + overflow-x: hidden; overflow-y: auto; font-family: inherit; line-height: 1.5;