Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid to have to wait to zoom after scrolling #17724

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 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: 0,
_lastScrollLeft: 0,

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

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

const { mainContainer } = appConfig;
calixteman marked this conversation as resolved.
Show resolved Hide resolved
// Using the values lastScrollTop and lastScrollLeft is a workaround to
// https://bugzilla.mozilla.org/show_bug.cgi?id=1881974.
// TODO: remove them once the bug is fixed.
({ 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 = () => {
({ scrollTop: this._lastScrollTop, scrollLeft: this._lastScrollLeft } =
mainContainer);
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 +2697,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 +2763,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