gblazex / smoothscroll

An extension for Google Chrome (150,000+ users)
https://chrome.google.com/webstore/detail/smoothscroll/nbokbjkabcmbfdlbddjidfmibcpneigj
Other
477 stars 99 forks source link

fix horizontal scrolling on linux #176

Closed Yanpas closed 5 years ago

Yanpas commented 5 years ago

Noticed this in console (verbose mode on):

sscr.js:624 [Violation] Added non-passive event listener to a scroll-blocking 'wheel' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952
addEvent @ sscr.js:624
(anonymous) @ sscr.js:737

Fixes #175

Yanpas commented 5 years ago

A lot of errors appeared imediately and scrolling has become weird a little, but at least it works: image

This isn't release ready. Before this commit function wheel wasn't even called (I was adding breakpoints to debugger)

gblazex commented 5 years ago

Thank you for taking the time and adding this PR.

I strongly believe passive listeners aren't the way to go, because they are meant for listeners that do not change the scroll events.

The sole purpose of SmoothScroll is to

  1. Block the native scroll events
  2. Add it's own animation

As you can see (1) is by definition about changing the scroll events.

That is why you receive the "preventDefault" inside passive listener error. In that case it is using a passive listener saying "hey I won't change anything inside this listener" and then trying to change things.

SmoothScroll doesn't directly detect Shift key scrolling.

https://github.com/gblazex/smoothscroll/blob/master/src/sscr.js#L343

It simply uses the deltaX properties of the wheel events.

It's the job of the OS to post deltaX instead of deltaY when the shift is down.

By placing a breakpoint at the line I just mentioned (343) you could check what deltaX and deltaY is when you are using the shift button.

Yanpas commented 5 years ago

deltax is 0, deltay is 120 no matter if i hold shift

gblazex commented 5 years ago

okay test this patch added at line 364 https://github.com/gblazex/smoothscroll/blob/master/src/sscr.js#L364

var isLinux =  /Linux/i.test(navigator.userAgent);
if (isLinux) { // issues #148 #176 
    var otherModifier = (event.ctrlKey || event.altKey || event.metaKey);
    if (event.shiftKey && !otherModifier) {
        deltaX = deltaX || deltaY;
        deltaY = 0;
    }
}
Yanpas commented 5 years ago

It works fine!

gblazex commented 5 years ago

just uploaded the next version that fixes this. Peace man, Blaze

Yanpas commented 5 years ago

Thank you