From 30969f8ab6b522c6123d95c36393b90bc07db2e0 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 28 Oct 2019 18:56:38 +0000 Subject: [PATCH] Desktop: Fixes #1867: Fix scrolling issue when clicking on internal link --- ElectronClient/app/gui/note-viewer/index.html | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ElectronClient/app/gui/note-viewer/index.html b/ElectronClient/app/gui/note-viewer/index.html index e2620c96481..f5f85f4fe71 100644 --- a/ElectronClient/app/gui/note-viewer/index.html +++ b/ElectronClient/app/gui/note-viewer/index.html @@ -161,7 +161,7 @@ } } - let ignoreNextScrollEvent = false; + let lastScrollEventTime = 0; ipc.setPercentScroll = (event) => { const percent = event.percent; @@ -170,7 +170,7 @@ checkScrollIID_ = null; } - ignoreNextScrollEvent = true; + lastScrollEventTime = Date.now(); setPercentScroll(percent); } @@ -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);