Drop a held edge-scroll step when the motion turns or the pointer moves to the other rail

Co-authored-by: Sameh Khamis <[email protected]>
This commit is contained in:
Manjunath PaparajuandSameh Khamis authored and Sameh Khamis committed 2026-11-14 13:41:07 -08:00
1 parent 81f3602134
commit 9261279639
1 file changed
+10 -2
+10 -2
View File
@@ -222,6 +222,12 @@ export function installRailEdgeScroll(doc = globalThis.document) {
const notch = stepped && cooled && speed >= NOTCH_DELTA; const notch = stepped && cooled && speed >= NOTCH_DELTA;
const flick = stepped && cooled && slowed && speed > Math.max(8, lastSpeed * 1.8); const flick = stepped && cooled && slowed && speed > Math.max(8, lastSpeed * 1.8);
if (!inGesture || turned || notch || flick) { if (!inGesture || turned || notch || flick) {
// A held step belongs to the motion it came from; a reversal or a new
// flick replaces it rather than queueing behind it.
if (turned && heldStep) {
win.clearTimeout(heldStep);
heldStep = 0;
}
travel = 0; travel = 0;
stepped = false; stepped = false;
peakSpeed = 0; peakSpeed = 0;
@@ -246,10 +252,12 @@ export function installRailEdgeScroll(doc = globalThis.document) {
} }
// Too soon after the last step: hold this one until the gap has passed. // Too soon after the last step: hold this one until the gap has passed.
if (heldStep) return; if (heldStep) return;
const heldRail = hot;
heldStep = win.setTimeout(() => { heldStep = win.setTimeout(() => {
heldStep = 0; heldStep = 0;
// The pointer may have left the strip meanwhile; then nothing steps. // The pointer may have left the strip, or moved to the other rail,
if (!hot) return; // meanwhile; then nothing steps.
if (!hot || hot !== heldRail) return;
steppedAt = win.performance?.now?.() ?? Date.now(); steppedAt = win.performance?.now?.() ?? Date.now();
step(direction); step(direction);
}, wait); }, wait);