From 817bcc3ba7b2aaad388bc5b2e5cda5ccf7b27766 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 9 Oct 2026 01:06:37 -0700 Subject: Restart wheel coast timing and respond immediately on reversal --- src/app.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/app.js b/src/app.js index 5d7d22b..52adce4 100644 --- a/src/app.js +++ b/src/app.js @@ -6428,9 +6428,18 @@ if (INTENT_URI) { if (e.timeStamp < smoothUntil || matchMedia('(pointer: coarse)').matches || !inScope(e.target)) return; e.preventDefault(); const px = e.deltaMode === 1 ? e.deltaY * 40 : e.deltaY; - // reverse turns brake first; same-way turns add to the coast already going - const keep = Math.sign(v) === Math.sign(px) ? v : 0; - coast(keep + (px * 3) / TAU); + // A reversal catches the old coast immediately. Discard its fractional + // step and frame clock too: after a busy frame, applying the NEW velocity + // to the OLD elapsed time made the first reverse step jump. Give the + // first notch a small response now, then coast the remaining distance. + if (v && px && Math.sign(v) !== Math.sign(px)) { + stop(); + const first = Math.sign(px) * Math.min(16, Math.abs(px * 3 / TAU) * 16); + window.scrollBy({ top: first, behavior: 'instant' }); + coast((px * 3 - first) / TAU); + } else { + coast(v + (px * 3) / TAU); + } }, { passive: false }); // anything else that moves the page takes over from a coast window.addEventListener('keydown', (e) => { if (/^(Arrow|Page|Home|End| )/.test(e.key)) stop(); }); -- cgit v1.2.3