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.

Fixes #17707.
  • Loading branch information
calixteman committed Feb 25, 2024
1 parent ca4ab06 commit e050f1f
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ const PDFViewerApplication = {
_isCtrlKeyDown: false,
_nimbusDataPromise: null,
_caretBrowsing: null,
_isScrolling: false,
_lastScrollTop: -1,
_lastScrollLeft: -1,

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

if (
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) &&
!("onscrollend" in document.documentElement)
) {
return;
}

const { mainContainer } = appConfig;
({ scrollTop: this._lastScrollTop, scrollLeft: this._lastScrollLeft } =
mainContainer);
const scroll = () => {
if (
this._lastScrollTop === mainContainer.scrollTop &&
this._lastScrollLeft === mainContainer.scrollLeft
) {
return;
}
mainContainer.removeEventListener("scroll", scroll, {
passive: true,
});
this._isScrolling = true;
const scrollend = () => {
this._lastScrollTop = mainContainer.scrollTop;
this._isScrolling = false;
mainContainer.addEventListener("scroll", scroll, {
passive: true,
});
mainContainer.removeEventListener("scrollend", scrollend);
mainContainer.removeEventListener("blur", scrollend);
};
mainContainer.addEventListener("scrollend", scrollend);
mainContainer.addEventListener("blur", scrollend);
};
mainContainer.addEventListener("scroll", scroll, {
passive: true,
});
},

get externalServices() {
Expand Down Expand Up @@ -2653,6 +2693,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,8 +2759,6 @@ 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 {
setZoomDisabledTimeout();
}
}

Expand Down

0 comments on commit e050f1f

Please sign in to comment.