From cfbc0e3ed3b19406fd800197ef9f635bad8acef1 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sun, 6 Dec 2026 02:37:56 +0800 Subject: [PATCH] fix(workbench): stop conversations and output panes at the last line (#8263) A strong downward trackpad gesture could pull the last reply above the composer and leave a blank strip. Vertical overscroll is now bounded in conversations, consoles and log viewers; scrolling toward the end releases the temporary space that holds a reader's place after a resize or fold; and a large pixel delta in a nested tool output stops at that output's edge. --- e2e/agentScroll.spec.ts | 18 ++++++++++++ e2e/console-ui.spec.ts | 1 + src/features/agents/Session.module.css | 1 + src/features/agents/session/Stream.tsx | 32 +++++++++++++++++---- src/features/agents/sessionState.test.tsx | 35 +++++++++++++++++++++++ src/features/app/newProject.module.css | 1 + src/styles/global.css | 5 ++++ src/ui/LogPane.module.css | 3 ++ 8 files changed, 91 insertions(+), 5 deletions(-) diff --git a/e2e/agentScroll.spec.ts b/e2e/agentScroll.spec.ts index eb4e46a53e..bccd817c78 100644 --- a/e2e/agentScroll.spec.ts +++ b/e2e/agentScroll.spec.ts @@ -83,6 +83,24 @@ test("keeps the conversation position on double-click", async ({ page }) => { await expect.poll(() => stream.evaluate((el, top) => Math.abs(el.scrollTop - top), before)).toBeLessThanOrEqual(1); }); +test("returns to the reply when scrolling down after the conversation viewport grows", async ({ page }) => { + const stream = await openHistory(page); + const bottomGap = () => + stream.evaluate((el) => el.getBoundingClientRect().bottom - el.lastElementChild!.getBoundingClientRect().bottom); + // A macOS trackpad can also scroll past this boundary during a fling. + await expect(stream).toHaveCSS("overscroll-behavior-y", "none"); + const initialGap = await bottomGap(); + await stream.hover(); + await page.mouse.wheel(0, -8); + await expect.poll(bottomGap).toBeLessThan(initialGap - 5); + + const size = page.viewportSize()!; + await page.setViewportSize({ ...size, height: size.height + 40 }); + await expect.poll(bottomGap).toBeGreaterThan(initialGap + 25); + await page.mouse.wheel(0, 80); + await expect.poll(async () => Math.abs((await bottomGap()) - initialGap)).toBeLessThanOrEqual(1); +}); + for (const placement of ["editor", "toolWindow"] as const) { test(`lets small upward wheel steps leave the end while replies stream in the ${placement}`, async ({ page }) => { // Streams into an 80-turn conversation for several seconds: close to 30 s on CI runners. diff --git a/e2e/console-ui.spec.ts b/e2e/console-ui.spec.ts index 8d4647e5dd..9999224eac 100644 --- a/e2e/console-ui.spec.ts +++ b/e2e/console-ui.spec.ts @@ -63,6 +63,7 @@ for (const kind of ["run", "debug", "services-run", "services-debug", "stacktrac const host = page.locator("#console-alignment-host"); const log = host.getByRole("log"); await expect(log).toBeVisible(); + await expect(log).toHaveCSS("overscroll-behavior-y", "none"); await log.focus(); await page.keyboard.press("Meta+f"); const search = host.getByRole("search", { name: "Find in console" }); diff --git a/src/features/agents/Session.module.css b/src/features/agents/Session.module.css index b46560ab06..f2224305de 100644 --- a/src/features/agents/Session.module.css +++ b/src/features/agents/Session.module.css @@ -261,6 +261,7 @@ min-width: 0; overflow-y: auto; overflow-x: hidden; + overscroll-behavior-y: none; overflow-anchor: none; padding: var(--space-3); display: flex; diff --git a/src/features/agents/session/Stream.tsx b/src/features/agents/session/Stream.tsx index feac89e02c..fdced79900 100644 --- a/src/features/agents/session/Stream.tsx +++ b/src/features/agents/session/Stream.tsx @@ -535,6 +535,23 @@ export function Stream({ shownRow.current = null; holdShownRow(); }, [holdShownRow]); + const scrollTowardEnd = useCallback( + (target: EventTarget | null) => { + scrollingUp.current = false; + const el = ref.current; + if (!el || !slack.current || scrollOwner(target, el) !== el) return; + // The spacer holds the reader at the scroll limit after a fold or resize. A downward + // gesture there may never fire a scroll event, so release it on input. + shownRow.current = null; + setSlack(0); + if (el.scrollHeight - el.clientHeight - el.scrollTop < 1) { + position.current = { top: el.scrollTop, stick: true }; + positions.set(key, position.current); + } + updateJumpVisibility(el); + }, + [key, positions, setSlack, updateJumpVisibility], + ); /** A diagram that drew after the last streamed chunk grows the conversation: keep following. */ const onDiagramDrawn = useCallback(() => { const el = ref.current; @@ -680,15 +697,20 @@ export function Stream({ if (owner !== el) { const room = e.deltaY < 0 ? owner.scrollTop : owner.scrollHeight - owner.clientHeight - owner.scrollTop; if (room <= 1) e.preventDefault(); + else if (e.deltaMode === WheelEvent.DOM_DELTA_PIXEL && Math.abs(e.deltaY) > room) { + // A single trackpad delta can cross the edge before the next wheel event. + e.preventDefault(); + owner.scrollTop += Math.sign(e.deltaY) * room; + } return; } markUserScroll(); if (e.deltaY < 0) stopFollowing(e.target); - else if (e.deltaY > 0) scrollingUp.current = false; + else if (e.deltaY > 0) scrollTowardEnd(owner); }; el.addEventListener("wheel", onWheel, { passive: false }); return () => el.removeEventListener("wheel", onWheel); - }, [markUserScroll, stopFollowing]); + }, [markUserScroll, scrollTowardEnd, stopFollowing]); /** * The reader opened or closed a section: put its header back where it was, in the run or * output that scrolls it and then in the conversation. Following stops when that leaves any @@ -849,7 +871,7 @@ export function Stream({ markUserScroll(); const y = e.touches.length === 1 ? e.touches[0]!.clientY : null; if (y !== null && touchY.current !== null && y > touchY.current) stopFollowing(e.target); - else if (y !== null && touchY.current !== null && y < touchY.current) scrollingUp.current = false; + else if (y !== null && touchY.current !== null && y < touchY.current) scrollTowardEnd(e.target); touchY.current = y; }} onKeyDown={(e) => { @@ -861,9 +883,9 @@ export function Stream({ e.key === "ArrowDown" || e.key === "PageDown" || e.key === "End" || - (e.key === " " && !e.shiftKey) + (e.key === " " && !e.shiftKey && !isInteractiveTarget(e.target)) ) - scrollingUp.current = false; + scrollTowardEnd(e.target); }} onPointerDown={(e) => { if (isInteractiveTarget(e.target)) return; diff --git a/src/features/agents/sessionState.test.tsx b/src/features/agents/sessionState.test.tsx index 247bd34ea1..1982392e46 100644 --- a/src/features/agents/sessionState.test.tsx +++ b/src/features/agents/sessionState.test.tsx @@ -935,6 +935,36 @@ describe("scrolling", () => { expect(el.scrollTop).toBe(1000); }); + it.each(["wheel", "touch", "End"])("clears fold space when scrolling down again with %s", async (method) => { + backend.entries.set("A", [ + { type: "thought", text: "Weighing it" }, + { type: "agent", text: "Answer A" }, + ]); + useAgents.setState({ entries: new Map(backend.entries) }); + render(); + await screen.findByText("Answer A"); + const { el, summary, slack } = foldingStream(60); + summary.getBoundingClientRect = () => ({ top: 900 - el.scrollTop }) as DOMRect; + fireEvent.click(summary); + el.scrollTop = 660; + fireEvent.scroll(el); + fireEvent.click(summary); + expect(slack()).toBe(60); + // Space on the fold header activates it; only scroll input should release the spacer. + fireEvent.keyDown(summary, { key: " " }); + expect(slack()).toBe(60); + + if (method === "wheel") fireEvent.wheel(el, { deltaY: 12 }); + else if (method === "touch") { + fireEvent.touchStart(el, { touches: [{ clientY: 100 }] }); + fireEvent.touchMove(el, { touches: [{ clientY: 88 }] }); + } else fireEvent.keyDown(el, { key: "End" }); + + expect(slack()).toBe(0); + expect(el.scrollTop).toBe(el.scrollHeight - el.clientHeight); + expect(useAgents.getState().scrollPositions.get("A")?.stick).toBe(true); + }); + it("scrolls the innermost container under the wheel and never hands it to the conversation", () => { const transcript: AgentEntry[] = [tool("live", { status: "running", output: "Tool output" })]; useAgents.setState({ entries: new Map([["A", transcript]]) }); @@ -957,6 +987,11 @@ describe("scrolling", () => { output.scrollTop = 100; expect(fireEvent.wheel(output, { deltaY: -4 })).toBe(true); expect(screen.queryByRole("button", { name: "Jump to Latest" })).toBeNull(); + // A large pixel delta stops at the output boundary in either direction. + expect(fireEvent.wheel(output, { deltaY: 150 })).toBe(false); + expect(output.scrollTop).toBe(200); + expect(fireEvent.wheel(output, { deltaY: -250 })).toBe(false); + expect(output.scrollTop).toBe(0); // A gesture that started in the conversation stays there when the output slides under it. now = 2000; expect(fireEvent.wheel(el, { deltaY: -4 })).toBe(true); diff --git a/src/features/app/newProject.module.css b/src/features/app/newProject.module.css index 320584b895..f313a8fdf1 100644 --- a/src/features/app/newProject.module.css +++ b/src/features/app/newProject.module.css @@ -226,6 +226,7 @@ color: var(--fg-strong); } .log { + overscroll-behavior-y: none; flex: 1; min-height: 0; margin: 0; diff --git a/src/styles/global.css b/src/styles/global.css index 8a615b66ec..53617d3c66 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -74,6 +74,11 @@ body { cursor: default; } +/* Output panes follow their last line. Keep macOS elastic offsets out of that position. */ +[role="log"] { + overscroll-behavior-y: none; +} + [data-scrollbar-drag-surface] { position: fixed; inset: 0; diff --git a/src/ui/LogPane.module.css b/src/ui/LogPane.module.css index df14c45950..3995a276e5 100644 --- a/src/ui/LogPane.module.css +++ b/src/ui/LogPane.module.css @@ -23,6 +23,9 @@ position: relative; overflow: hidden; } +.output :global(.cm-scroller) { + overscroll-behavior-y: none; +} .log { flex: 1; min-height: 0;