Skip to content
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
40 changes: 28 additions & 12 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down