From ccd3a33bc2e87475eceb838427537799fae36d97 Mon Sep 17 00:00:00 2001 From: Fardel Pierre Date: Thu, 8 Oct 2026 12:29:49 +0200 Subject: [PATCH 1/2] fix(viewport): scroll the message list proportionally to the wheel delta mousewheelHandler moved a fixed 3 rows per wheel event and only read the sign of the delta. Trackpads and free-spinning wheels emit many small events per gesture, so a short swipe jumped through dozens of messages. Convert deltaY to rows with _getLineHeight(), honouring deltaMode, and accumulate sub-row deltas until they make a full row. Horizontal gestures are ignored, and the event is prevented so the container cannot also scroll natively under the virtual viewport. Legacy mousewheel and DOMMouseScroll events keep the historical 3-row step. --- js/viewport.js | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/js/viewport.js b/js/viewport.js index 882a69fe1..029a62db2 100644 --- a/js/viewport.js +++ b/js/viewport.js @@ -1429,20 +1429,52 @@ ViewPort_Scroller = Class.create({ mousewheelHandler: function(e) { - var delta = e.wheelDelta || 0; + var lh, px, rows; + + /* Legacy events (mousewheel / DOMMouseScroll) carry no pixel + * delta: keep the historical fixed step of 3 rows per notch. */ + if (Object.isUndefined(e.deltaY)) { + px = e.wheelDelta || 0; + if (e.detail) { + px = e.detail * -1; + } + if (px) { + this.moveScroll(this.currentOffset() + (Math.min(this.vp.getPageSize(), 3) * (px > 0 ? -1 : 1))); + } + return; + } - if (e.detail) { - delta = e.detail * -1; + /* Horizontal gesture: not ours. */ + if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) { + return; } - if (e.deltaY) { - delta = e.deltaY * -1; + + /* Scroll proportionally to the wheel delta. Moving a fixed 3 rows + * per event made trackpads and free-spinning wheels, which emit + * many small events per gesture, scroll far too fast. Small deltas + * are accumulated until they add up to a full row. */ + lh = this.vp._getLineHeight() || 1; + px = e.deltaY; + if (e.deltaMode === 1) { + px *= lh; + } else if (e.deltaMode === 2) { + px *= lh * this.vp.getPageSize(); } - if (!Object.isUndefined(e.wheelDeltaY)) { - delta = e.wheelDeltaY; + + if (this.wheelacc && ((this.wheelacc > 0) !== (px > 0))) { + this.wheelacc = 0; } + this.wheelacc = (this.wheelacc || 0) + px; + + rows = (this.wheelacc > 0) + ? Math.floor(this.wheelacc / lh) + : Math.ceil(this.wheelacc / lh); + this.wheelacc -= rows * lh; + + e.preventDefault(); - if (delta) { - this.moveScroll(this.currentOffset() + (Math.min(this.vp.getPageSize(), 3) * (delta > 0 ? -1 : 1))); + if (rows) { + this.moveScroll(this.currentOffset() + rows); } }, From 834619ebc17cd36559f905a84f9b12c27fbf3f72 Mon Sep 17 00:00:00 2001 From: Fardel Pierre Date: Thu, 8 Oct 2026 14:07:22 +0200 Subject: [PATCH 2/2] fix(viewport): do not treat a zero wheel delta as a direction change A zero vertical delta made a positive accumulator look like a reversal and dropped a pending partial row when scrolling down, while a negative accumulator was kept. Zero has no direction: only reset on a non-zero delta of the opposite sign. --- js/viewport.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/viewport.js b/js/viewport.js index 029a62db2..4303e385c 100644 --- a/js/viewport.js +++ b/js/viewport.js @@ -1461,7 +1461,7 @@ ViewPort_Scroller = Class.create({ px *= lh * this.vp.getPageSize(); } - if (this.wheelacc && ((this.wheelacc > 0) !== (px > 0))) { + if (px && this.wheelacc && ((this.wheelacc > 0) !== (px > 0))) { this.wheelacc = 0; } this.wheelacc = (this.wheelacc || 0) + px;