totu / Swipe2Nav

Firefox Add-on to enable two-finger left and right gestures to navigate browser history
MIT License
18 stars 4 forks source link

Horizontal scrolling timeout implementation is kinda useless for some (maybe all) smooth scrolling enabled track pad/mouse #14

Open notwatermango opened 2 years ago

notwatermango commented 2 years ago

Below code is called whenever user is scrolling an element while not at the edge of element.

setTimeout(() => {
      timeout = false;
}, 2000);

This actually leads to (kinda) nothing for smooth scrolls.

Above code will be called multiple times (around 50 times for one swipe in smooth scroll track pad) which will set timeout to false after 2s of each calls.

For example if it's called at time 0000 and it's called again at 1500, the first one will set timeout to false at 2000. If we scroll at 2001 at the edge, the navigation function will go in and users get navigated at 2001 because timeout is set to false.

In above case what we want is navigation timeout set to true until 3500. (right?)

I don't know any other fix except counting all calls, here are the illustration.

someCounter++;
setTimeout(() => {
      someCounter--;
}, 2000);

// ..

// disabling navigation
if (someCounter) // do not navigate

Above code works for me. Although it looks kinda ugly and probably not the best practice.

What do you think?

totu commented 2 years ago

If you can make a pull request I can merge it