Skip to content

Commit

Permalink
Avoid to have to wait to zoom after scrolling
Browse files Browse the repository at this point in the history
Allow to zoom with the wheel once the scrolling is finished.
It's now possible to know that thanks to the scrollend event.
Keep the previous way to work for browsers not supporting the
scrollend event.

Fixes #17707.
  • Loading branch information
calixteman committed Feb 24, 2024
1 parent 346efe9 commit 655815e
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ const PDFViewerApplication = {
_isCtrlKeyDown: false,
_nimbusDataPromise: null,
_caretBrowsing: null,
_isScrolling: false,
_isScrollEndSupported: true,

// Called once when the document is loaded.
async initialize(appConfig) {
Expand Down Expand Up @@ -683,6 +685,33 @@ const PDFViewerApplication = {
} else {
throw new Error("Not implemented: run");
}

if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
this._isScrollEndSupported = "onscrollend" in document.documentElement;
}
if (
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
this._isScrollEndSupported
) {
const { mainContainer } = appConfig;
mainContainer.addEventListener(
"scroll",
() => {
if (this._isScrolling) {
return;
}
this._isScrolling = true;
mainContainer.addEventListener(
"scrollend",
() => {
this._isScrolling = false;
},
{ once: true }
);
},
{ passive: true }
);
}
},

get externalServices() {
Expand Down Expand Up @@ -2653,6 +2682,7 @@ function webViewerWheel(evt) {
evt.preventDefault();
// NOTE: this check must be placed *after* preventDefault.
if (
PDFViewerApplication._isScrolling ||
zoomDisabledTimeout ||
document.visibilityState === "hidden" ||
PDFViewerApplication.overlayManager.active
Expand Down Expand Up @@ -2718,7 +2748,10 @@ function webViewerWheel(evt) {
// left corner is restored. When the mouse wheel is used, the position
// under the cursor should be restored instead.
PDFViewerApplication._centerAtPos(previousScale, evt.clientX, evt.clientY);
} else {
} else if (
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) &&
!PDFViewerApplication._isScrollEndSupported
) {
setZoomDisabledTimeout();
}
}
Expand Down

0 comments on commit 655815e

Please sign in to comment.