fix(webui): respect middle-click autoscroll (#6612)
* fix(webui): respect middle-click autoscroll Co-authored-by: ovo-agentx <351813579+ovo-agentx@users.noreply.github.com> * fix(webui): arbitrate scrolling from actual viewport movement Remove the middle-button gesture model. Attribute actual viewport movement at the camera write boundary so native scrolling yields ownership without predicting browser gesture state or nested scroll targets. Exclude layout clamping, preserve application navigation, and reconcile pending scrolls before geometry, animation, or history-anchor writes can overwrite them. Co-authored-by: ovo-agentx <351813579+ovo-agentx@users.noreply.github.com> --------- Co-authored-by: ovo-agentx <351813579+ovo-agentx@users.noreply.github.com>
This commit is contained in:
1 parent
86c98c8cf2
commit
5c72ced2fe
7 files changed
+227
-15
No files matched your search
@@ -12,6 +12,8 @@ function cameraHarness(prefersReducedMotion = false) {
|
||||
const frames = new Map<number, FrameRequestCallback>();
|
||||
const viewport: ThreadCameraViewport = {
|
||||
scrollTop: 0,
|
||||
scrollHeight: 1_000_000,
|
||||
clientHeight: 500,
|
||||
};
|
||||
const scheduler: ThreadCameraScheduler = {
|
||||
request: vi.fn((callback) => {
|
||||
@@ -115,6 +117,37 @@ describe("ThreadCameraController", () => {
|
||||
expect(camera.isFollowing()).toBe(false);
|
||||
});
|
||||
|
||||
it("separates external movement from camera writes and layout clamping", () => {
|
||||
const { camera, viewport } = cameraHarness();
|
||||
viewport.scrollHeight = 2_000;
|
||||
camera.jumpTo(1_500);
|
||||
expect(camera.observeScroll()).toBe(0);
|
||||
camera.jumpTo(900);
|
||||
expect(camera.observeScroll()).toBe(0);
|
||||
viewport.scrollTop = 880;
|
||||
expect(camera.observeScroll()).toBe(-20);
|
||||
viewport.scrollHeight = 1_000;
|
||||
viewport.scrollTop = 500;
|
||||
expect(camera.observeScroll()).toBe(0);
|
||||
viewport.scrollHeight = 2_000;
|
||||
expect(camera.observeScroll()).toBe(0);
|
||||
viewport.scrollTop = 0;
|
||||
expect(camera.observeScroll()).toBe(-500);
|
||||
});
|
||||
|
||||
it("does not overwrite external movement before its scroll event arrives", () => {
|
||||
const { camera, viewport, advance, frames } = cameraHarness();
|
||||
camera.jumpTo(1_000);
|
||||
camera.navigateTo(2_000);
|
||||
advance(16);
|
||||
const readingTop = viewport.scrollTop - 20;
|
||||
viewport.scrollTop = readingTop;
|
||||
advance(16);
|
||||
expect(viewport.scrollTop).toBe(readingTop);
|
||||
expect(frames).toHaveLength(0);
|
||||
expect(camera.observeScroll()).toBe(-20);
|
||||
});
|
||||
|
||||
it("eases explicit long-distance navigation across frames", () => {
|
||||
const { camera, viewport, advance } = cameraHarness();
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ function motionHarness(initial?: Partial<ThreadMotionGeometry>) {
|
||||
cameraFollowing = false;
|
||||
}),
|
||||
dispose: vi.fn(),
|
||||
observeScroll: vi.fn(() => 0),
|
||||
reset: vi.fn(() => { cameraFollowing = false; }),
|
||||
jumpTo: vi.fn(),
|
||||
followTo: vi.fn(() => "settled" as const),
|
||||
isFollowing: vi.fn(() => cameraFollowing),
|
||||
@@ -447,6 +449,7 @@ describe("ThreadMotionCoordinator", () => {
|
||||
expect(coordinator.observeScroll(false)).toBe("user");
|
||||
expect(coordinator.snapshot().mode).toBe("browsing-history");
|
||||
|
||||
coordinator.handleUserScrollIntent(true, true);
|
||||
expect(coordinator.observeScroll(true)).toBe("automatic");
|
||||
expect(coordinator.snapshot().mode).toBe("anchor-prompt");
|
||||
});
|
||||
|
||||
@@ -979,6 +979,89 @@ describe("ThreadViewport", () => {
|
||||
.not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps uncommanded scrolling user-owned through layout changes and a tail reversal", async () => {
|
||||
const { scroller } = await renderPromptRailViewport();
|
||||
expect(scroller.scrollTop).toBe(1_200);
|
||||
|
||||
act(() => {
|
||||
scroller.scrollTop = 1_180;
|
||||
fireEvent.scroll(scroller);
|
||||
window.dispatchEvent(new Event("resize"));
|
||||
});
|
||||
await flushAnimationFrame();
|
||||
expect(scroller.scrollTop).toBe(1_180);
|
||||
|
||||
act(() => {
|
||||
scroller.scrollTop = 1_000;
|
||||
fireEvent.scroll(scroller);
|
||||
scroller.scrollTop = 1_100;
|
||||
fireEvent.scroll(scroller);
|
||||
});
|
||||
// A partial return must not let later layout clamping resume follow.
|
||||
act(() => {
|
||||
Object.defineProperty(scroller, "scrollHeight", { configurable: true, value: 1_500 });
|
||||
scroller.scrollTop = 900;
|
||||
fireEvent.scroll(scroller);
|
||||
window.dispatchEvent(new Event("resize"));
|
||||
});
|
||||
await flushAnimationFrame();
|
||||
act(() => {
|
||||
Object.defineProperty(scroller, "scrollHeight", { configurable: true, value: 1_800 });
|
||||
window.dispatchEvent(new Event("resize"));
|
||||
});
|
||||
await flushAnimationFrame();
|
||||
expect(scroller.scrollTop).toBe(900);
|
||||
|
||||
act(() => {
|
||||
scroller.scrollTop = 1_200;
|
||||
fireEvent.scroll(scroller);
|
||||
});
|
||||
await flushAnimationFrame();
|
||||
expect(scroller.scrollTop).toBe(1_200);
|
||||
|
||||
act(() => {
|
||||
scroller.scrollTop = 1_000;
|
||||
fireEvent.scroll(scroller);
|
||||
window.dispatchEvent(new Event("resize"));
|
||||
});
|
||||
await flushAnimationFrame();
|
||||
expect(scroller.scrollTop).toBe(1_000);
|
||||
});
|
||||
|
||||
it.each(["scroll-first", "layout-first"])("keeps the reading position through output and completion with %s delivery", async (ordering) => {
|
||||
const threaded: UIMessage[] = [
|
||||
{ id: "u1", role: "user", content: "question", turnId: "turn-1", createdAt: 1 },
|
||||
{ id: "a1", role: "assistant", content: "answer", turnId: "turn-1", isStreaming: true, createdAt: 2 },
|
||||
];
|
||||
const { container, rerender } = render(
|
||||
<ThreadViewport messages={threaded} isStreaming activeTurnId="turn-1" composer={<div />} />,
|
||||
);
|
||||
const scroller = getScroller(container);
|
||||
mockScrollGeometry(scroller, 1_900, 500, 1_400);
|
||||
act(() => window.dispatchEvent(new Event("resize")));
|
||||
await flushAnimationFrame();
|
||||
|
||||
act(() => {
|
||||
scroller.scrollTop = 1_000;
|
||||
if (ordering === "scroll-first") fireEvent.scroll(scroller);
|
||||
Object.defineProperty(scroller, "scrollHeight", { configurable: true, value: 2_100 });
|
||||
rerender(
|
||||
<ThreadViewport messages={[threaded[0], { ...threaded[1], content: "answer with more output" }]} isStreaming activeTurnId="turn-1" composer={<div />} />,
|
||||
);
|
||||
});
|
||||
await flushAnimationFrame();
|
||||
expect(scroller.scrollTop).toBe(1_000);
|
||||
|
||||
act(() => {
|
||||
Object.defineProperty(scroller, "scrollHeight", { configurable: true, value: 2_300 });
|
||||
rerender(
|
||||
<ThreadViewport messages={[threaded[0], { ...threaded[1], content: "final answer", isStreaming: false }]} isStreaming={false} composer={<div />} />,
|
||||
);
|
||||
});
|
||||
await flushAnimationFrame();
|
||||
expect(scroller.scrollTop).toBe(1_000);
|
||||
});
|
||||
|
||||
it("tracks the message content edge independently of trailing space and motion ownership", () => {
|
||||
const resizeObserver = stubResizeObserver();
|
||||
try {
|
||||
@@ -1700,6 +1783,19 @@ describe("ThreadViewport", () => {
|
||||
|
||||
expect(scroller.scrollTop).toBe(260);
|
||||
expect(replacement.getBoundingClientRect().top).toBe(120);
|
||||
|
||||
// ResizeObserver may arrive before the next native scroll event.
|
||||
hitTarget = replacement;
|
||||
scroller.scrollTop = 240;
|
||||
anchorDocumentTop += 60;
|
||||
scrollHeight += 60;
|
||||
act(() => { observer?.callback([], observer); });
|
||||
expect(scroller.scrollTop).toBe(240);
|
||||
act(() => { fireEvent.scroll(scroller); });
|
||||
anchorDocumentTop += 40;
|
||||
scrollHeight += 40;
|
||||
act(() => { observer?.callback([], observer); });
|
||||
expect(scroller.scrollTop).toBe(280);
|
||||
} finally {
|
||||
hitTest.restore();
|
||||
resizeObserver.restore();
|
||||
|
||||
Reference in new issue
Block a user