From 287776483f01d75a4aef4df6850cf09de233bacd Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Fri, 1 Aug 2025 19:06:14 +0200 Subject: [PATCH] Trigger a fake scrollend event in case it hasn't been triggered by the browser (bug 1957680) This way, it should unblock zooming with ctrl+wheel after scrolling. --- web/app.js | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/web/app.js b/web/app.js index f48643138..69f5ea298 100644 --- a/web/app.js +++ b/web/app.js @@ -2227,19 +2227,18 @@ const PDFViewerApplication = { mainContainer); } + let scrollendTimeoutID, scrollAbortController; const scrollend = () => { if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { ({ scrollTop: this._lastScrollTop, scrollLeft: this._lastScrollLeft } = mainContainer); } - - this._isScrolling = false; - mainContainer.addEventListener("scroll", scroll, { - passive: true, - signal, - }); - mainContainer.removeEventListener("scrollend", scrollend); - mainContainer.removeEventListener("blur", scrollend); + clearTimeout(scrollendTimeoutID); + if (this._isScrolling) { + scrollAbortController.abort(); + scrollAbortController = null; + this._isScrolling = false; + } }; const scroll = () => { if (this._isCtrlKeyDown) { @@ -2253,10 +2252,27 @@ const PDFViewerApplication = { return; } - mainContainer.removeEventListener("scroll", scroll); - this._isScrolling = true; - mainContainer.addEventListener("scrollend", scrollend, { signal }); - mainContainer.addEventListener("blur", scrollend, { signal }); + if (!this._isScrolling) { + scrollAbortController = new AbortController(); + const abortSignal = AbortSignal.any([ + scrollAbortController.signal, + signal, + ]); + + mainContainer.addEventListener("scrollend", scrollend, { + signal: abortSignal, + }); + mainContainer.addEventListener("blur", scrollend, { + signal: abortSignal, + }); + this._isScrolling = true; + } + clearTimeout(scrollendTimeoutID); + // Why 100 ? Because of: + // https://developer.chrome.com/blog/scrollend-a-new-javascript-event + // Maybe we could find a better value... ideally the `scrollend` event + // should be correctly fired. + scrollendTimeoutID = setTimeout(scrollend, 100); }; mainContainer.addEventListener("scroll", scroll, { passive: true,