Skip to content

Commit 3ddd828

Browse files
committed
Use WheelEvent.deltaMode when available and 0
Works around a regression on Chrome 94, where non-linear scrolling greatly confused the wheel unit estimation code. See https://discuss.codemirror.net/t/scrolling-is-badly-impacted-by-chrome-94-0-4606-61/3567/3
1 parent 73a5c21 commit 3ddd828

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/display/scroll_events.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ export function wheelEventPixels(e) {
4141

4242
export function onScrollWheel(cm, e) {
4343
let delta = wheelEventDelta(e), dx = delta.x, dy = delta.y
44+
let pixelsPerUnit = wheelPixelsPerUnit
45+
if (event.deltaMode === 0) {
46+
dx = e.deltaX
47+
dy = e.deltaY
48+
pixelsPerUnit = 1
49+
}
4450

4551
let display = cm.display, scroll = display.scroller
4652
// Quit if there's nothing to scroll here
@@ -69,10 +75,10 @@ export function onScrollWheel(cm, e) {
6975
// estimated pixels/delta value, we just handle horizontal
7076
// scrolling entirely here. It'll be slightly off from native, but
7177
// better than glitching out.
72-
if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
78+
if (dx && !gecko && !presto && pixelsPerUnit != null) {
7379
if (dy && canScrollY)
74-
updateScrollTop(cm, Math.max(0, scroll.scrollTop + dy * wheelPixelsPerUnit))
75-
setScrollLeft(cm, Math.max(0, scroll.scrollLeft + dx * wheelPixelsPerUnit))
80+
updateScrollTop(cm, Math.max(0, scroll.scrollTop + dy * pixelsPerUnit))
81+
setScrollLeft(cm, Math.max(0, scroll.scrollLeft + dx * pixelsPerUnit))
7682
// Only prevent default scrolling if vertical scrolling is
7783
// actually possible. Otherwise, it causes vertical scroll
7884
// jitter on OSX trackpads when deltaX is small and deltaY
@@ -85,15 +91,15 @@ export function onScrollWheel(cm, e) {
8591

8692
// 'Project' the visible viewport to cover the area that is being
8793
// scrolled into view (if we know enough to estimate it).
88-
if (dy && wheelPixelsPerUnit != null) {
89-
let pixels = dy * wheelPixelsPerUnit
94+
if (dy && pixelsPerUnit != null) {
95+
let pixels = dy * pixelsPerUnit
9096
let top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight
9197
if (pixels < 0) top = Math.max(0, top + pixels - 50)
9298
else bot = Math.min(cm.doc.height, bot + pixels + 50)
9399
updateDisplaySimple(cm, {top: top, bottom: bot})
94100
}
95101

96-
if (wheelSamples < 20) {
102+
if (wheelSamples < 20 && e.deltaMode !== 0) {
97103
if (display.wheelStartX == null) {
98104
display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop
99105
display.wheelDX = dx; display.wheelDY = dy

0 commit comments

Comments
 (0)