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
@@ -4,6 +4,8 @@ const SETTLE_DISTANCE_PX = 0.5;
|
||||
|
||||
export interface ThreadCameraViewport {
|
||||
scrollTop: number;
|
||||
scrollHeight: number;
|
||||
clientHeight: number;
|
||||
scrollTo?: (options?: ScrollToOptions) => void;
|
||||
}
|
||||
|
||||
@@ -45,6 +47,8 @@ export class ThreadCameraController {
|
||||
private target = 0;
|
||||
private lastTimestamp: number | null = null;
|
||||
private deadline = 0;
|
||||
private lastScrollTop: number | null = null;
|
||||
private lastViewport: ThreadCameraViewport | null = null;
|
||||
|
||||
constructor(
|
||||
getViewport: () => ThreadCameraViewport | null,
|
||||
@@ -56,6 +60,28 @@ export class ThreadCameraController {
|
||||
this.prefersReducedMotion = options.prefersReducedMotion ?? defaultPrefersReducedMotion;
|
||||
}
|
||||
|
||||
private scrollDelta(viewport: ThreadCameraViewport): number {
|
||||
if (viewport !== this.lastViewport || this.lastScrollTop === null) return 0;
|
||||
// Layout can clamp the old position to a shorter page. Only movement
|
||||
// beyond that clamp, or beyond our own last write, comes from outside.
|
||||
const max = Math.max(0, viewport.scrollHeight - viewport.clientHeight);
|
||||
return viewport.scrollTop - Math.min(this.lastScrollTop, max);
|
||||
}
|
||||
|
||||
observeScroll(): number {
|
||||
const viewport = this.getViewport();
|
||||
if (!viewport) return 0;
|
||||
const delta = this.scrollDelta(viewport);
|
||||
this.lastScrollTop = viewport.scrollTop;
|
||||
this.lastViewport = viewport;
|
||||
return delta;
|
||||
}
|
||||
|
||||
reset(): void {
|
||||
this.cancel();
|
||||
this.lastScrollTop = null;
|
||||
}
|
||||
|
||||
isFollowing(): boolean {
|
||||
return this.phase === "following";
|
||||
}
|
||||
@@ -100,6 +126,8 @@ export class ThreadCameraController {
|
||||
return "settled";
|
||||
}
|
||||
|
||||
this.lastScrollTop = current;
|
||||
this.lastViewport = viewport;
|
||||
this.phase = "following";
|
||||
this.lastTimestamp = this.scheduler.now();
|
||||
this.deadline = this.lastTimestamp + (this.prefersReducedMotion()
|
||||
@@ -130,6 +158,12 @@ export class ThreadCameraController {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Math.abs(this.scrollDelta(viewport)) > SETTLE_DISTANCE_PX) {
|
||||
// Do not overwrite browser movement while its scroll event is queued.
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
const previousTimestamp = this.lastTimestamp ?? timestamp;
|
||||
const remainingMs = Math.max(0, this.deadline - timestamp);
|
||||
if (remainingMs === 0) {
|
||||
@@ -157,5 +191,7 @@ export class ThreadCameraController {
|
||||
// Test DOMs can expose read-only scrollTop; browsers keep this writable.
|
||||
}
|
||||
}
|
||||
this.lastScrollTop = viewport.scrollTop;
|
||||
this.lastViewport = viewport;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user