Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(chat): keep scroll-up progress when the bottom-stick pins back (MUL-10304) (#11701)
Bohan Jiang392ca3d8463b
diff --git a/packages/views/common/task-transcript/transcript-follow.test.ts b/packages/views/common/task-transcript/transcript-follow.test.tsindex 328b74f1d0..0b5c745269 100644--- a/packages/views/common/task-transcript/transcript-follow.test.ts+++ b/packages/views/common/task-transcript/transcript-follow.test.ts@@ -187,6 +187,59 @@ describe("createLiveEndFollow", () => {expect(follow.isFollowing()).toBe(false);});+ it("a pin back into the edge zone does not erase the reader's progress", () => {+ // Regression (MUL-10304): scrolling up mounts an older row whose measured+ // height moves the viewport further in the same scroll event, so that+ // notch is pinned back. Landing back in the edge zone used to count as the+ // reader returning, wiping what they had taken — every attempt started+ // from zero and the list could not be scrolled at all.+ const { follow, tick } = makeFollow();+ follow.input(100);+ expect(follow.onScroll(100)).toBe(false); // 100px taken+ follow.endInputFrame();+ tick(400);+ follow.input(100);+ expect(follow.onScroll(869)).toBe(true); // row above mounted: pinned+ follow.endInputFrame();+ follow.onAtEdgeChange(false);+ expect(follow.onScroll(0)).toBe(false); // the pin lands+ follow.onAtEdgeChange(true);+ tick(400);+ follow.input(100);+ expect(follow.onScroll(100)).toBe(false); // 200px taken in total+ expect(follow.isFollowing()).toBe(false);+ });++ it("attributes a scroll that differs from its input by sub-pixel rounding", () => {+ // The surface snaps scroll offsets to device pixels, so a fractional+ // trackpad delta, or a list resting half a pixel above its end, never+ // moves by exactly the input. That is still the reader's own scroll.+ const { follow, tick } = makeFollow();+ tick(1000);+ follow.input(100);+ expect(follow.onScroll(100.5)).toBe(false);+ follow.endInputFrame();+ tick(16);+ follow.input(4.37);+ expect(follow.onScroll(105.5)).toBe(false);+ expect(follow.isFollowing()).toBe(true);+ });++ it("rounding slack never outlives the reader's claim", () => {+ // The reader has taken exactly the threshold and their claim is spent. A+ // 1px system shift inside the motion window is not theirs: crediting it+ // would release the follow and leave the next reply growth off screen.+ const { follow, tick } = makeFollow();+ tick(1000);+ follow.input(FOLLOW_EDGE_THRESHOLD);+ expect(follow.onScroll(FOLLOW_EDGE_THRESHOLD)).toBe(false);+ follow.endInputFrame();+ tick(100);+ expect(follow.onScroll(FOLLOW_EDGE_THRESHOLD + 1)).toBe(true);+ expect(follow.isFollowing()).toBe(true);+ expect(follow.onResize(FOLLOW_EDGE_THRESHOLD + 181)).toBe(true);+ });+it("pins displacement that lands inside the intent window", () => {// The final chunk of a reply has a whole window to land in after any// small nudge; the pin decision must not hide behind a timer, becausediff --git a/packages/views/common/task-transcript/transcript-follow.ts b/packages/views/common/task-transcript/transcript-follow.tsindex 8696d01f98..45945a364b 100644--- a/packages/views/common/task-transcript/transcript-follow.ts+++ b/packages/views/common/task-transcript/transcript-follow.ts@@ -24,7 +24,8 @@// verdict) — immediately, with no intent-window timer for a final event to// hide behind — but never during an active touch or while the mouse is held// down (text selection autoscroll must not be fought).-// - Arriving back within the edge zone re-engages the follow.+// - Arriving back within the edge zone re-engages a released follow. While+// still following, that arrival is usually our own pin and erases nothing.//// The state machine is direction-agnostic: callers feed it away-positive// input deltas and the current distance from THEIR live end (`scrollTop` for@@ -43,6 +44,14 @@ export const FOLLOW_EDGE_THRESHOLD = 120;// after the next animation frame.const MOTION_SETTLE_WINDOW_MS = 300;+// The surface snaps scroll offsets to device pixels, so its displacement can+// differ from the input behind it by up to a pixel: fractional trackpad deltas,+// or a list resting half a pixel short of its end. A system shift is pixels.+// The slack is bounded by the claim it rounds: once the reader's input is+// spent, even a 1px shift is the system's.+const SCROLL_ROUNDING_PX = 1;+const roundingSlack = (claim: number) => Math.min(SCROLL_ROUNDING_PX, claim);+// WheelEvent.deltaMode 1 (lines) / 2 (pages) conversion.export const LINE_SCROLL_PX = 40;@@ -110,11 +119,7 @@ export function createLiveEndFollow(now: () => number = () => Date.now()): LiveEconst inputFresh = () => now() - lastInputAt < MOTION_SETTLE_WINDOW_MS;const motionFresh = () => now() - lastMotionAt < MOTION_SETTLE_WINDOW_MS;- // Carry is spent in fractional steps, so its running total drifts from the- // surface's own arithmetic by a few ulps. Scaled to the amount at hand, a- // gap this small is rounding — the system moving the viewport is pixels.- const withinCarry = (amount: number) =>- amount <= motionCarry + Math.max(1, motionCarry) * 1e-9;+ const withinCarry = (amount: number) => amount <= motionCarry + roundingSlack(motionCarry);const pinVerdict = (distance: number): boolean =>following && !mouseHeld && !scrollbarDrag && !touchHeld && distance > 0;@@ -173,7 +178,9 @@ export function createLiveEndFollow(now: () => number = () => Date.now()): LiveEscrollbarDrag = false;},onAtEdgeChange(atEdge: boolean) {- if (!active || !atEdge) return;+ // Arriving while still following is the pin bringing the reader back,+ // not the reader returning: keep what they have taken (see header).+ if (!active || !atEdge || following) return;following = true;awayBudget = 0;towardBudget = 0;@@ -237,7 +244,7 @@ export function createLiveEndFollow(now: () => number = () => Date.now()): LiveEconst attributed = Math.min(awayBudget, moved);awayBudget -= attributed;// Touch displacement need not match finger travel pixel-for-pixel.- if (touchHeld || attributed === moved) {+ if (touchHeld || moved - attributed <= roundingSlack(attributed)) {awayTaken += moved;motionDirection = 1;motionSource = touchHeld ? "touch" : "input";@@ -251,7 +258,7 @@ export function createLiveEndFollow(now: () => number = () => Date.now()): LiveE} else if (moved < 0 && inputFresh() && towardBudget > 0) {const attributed = Math.min(towardBudget, -moved);towardBudget -= attributed;- if (touchHeld || attributed === -moved) {+ if (touchHeld || -moved - attributed <= roundingSlack(attributed)) {awayTaken = Math.max(0, awayTaken + moved);motionDirection = -1;motionSource = touchHeld ? "touch" : "input";