Skip to content

Commit

Permalink
Desktop: Fixes laurent22#1867: Fix scrolling issue when clicking on i…
Browse files Browse the repository at this point in the history
…nternal link
  • Loading branch information
laurent22 authored and scoroi committed Nov 10, 2019
1 parent 94b78b7 commit 0ab5c99
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions ElectronClient/app/gui/note-viewer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
}
}

let ignoreNextScrollEvent = false;
let lastScrollEventTime = 0;
ipc.setPercentScroll = (event) => {
const percent = event.percent;

Expand All @@ -170,7 +170,7 @@
checkScrollIID_ = null;
}

ignoreNextScrollEvent = true;
lastScrollEventTime = Date.now();
setPercentScroll(percent);
}

Expand Down Expand Up @@ -293,10 +293,20 @@
}

contentElement.addEventListener('scroll', webviewLib.logEnabledEventHandler(e => {
if (ignoreNextScrollEvent) {
ignoreNextScrollEvent = false;
console.info('contentElement.scroll', lastScrollEventTime);

// If the last scroll event was done by the user, lastScrollEventTime is set and
// we can use that to skip the event handling. We skip it because in that case
// the scroll position has already been updated. Also we add a 200ms interval
// because otherwise it's most likely a glitch where we called ipc.setPercentScroll
// but the scroll event listener has not been called.
if (lastScrollEventTime && Date.now() - lastScrollEventTime < 200) {
lastScrollEventTime = 0;
return;
}

lastScrollEventTime = 0;

const percent = currentPercentScroll();
setPercentScroll(percent);

Expand Down

0 comments on commit 0ab5c99

Please sign in to comment.