mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 02:05:37 +02:00
Rip out the current implementation of PDFHistory
The current implementation of `PDFHistory` contains a number of smaller bugs, which are *very* difficult to address without breaking other parts of its code. Possibly the main issue with the current implementation, is that I wrote it quite some time ago, and at the time my understanding of the various edge-cases the code has to deal with was quite limited. Currently `PDFHistory` may, despite most of those cases being fixed, in certain edge-cases lock-up the browser history, essentially preventing the user from navigating back/forward. Hence rather than trying to iterate on `PDFHistory` to make it better, the only viable approach is unfortunately rip it out in its entirety and re-write it from scratch.
This commit is contained in:
parent
2656825432
commit
28ce3b6185
4 changed files with 31 additions and 472 deletions
63
web/app.js
63
web/app.js
|
@ -89,7 +89,6 @@ const DefaultExternalServices = {
|
|||
|
||||
let PDFViewerApplication = {
|
||||
initialBookmark: document.location.hash.substring(1),
|
||||
initialDestination: null,
|
||||
initialized: false,
|
||||
fellback: false,
|
||||
appConfig: null,
|
||||
|
@ -931,20 +930,11 @@ let PDFViewerApplication = {
|
|||
if (!PDFJS.disableHistory && !this.isViewerEmbedded) {
|
||||
// The browsing history is only enabled when the viewer is standalone,
|
||||
// i.e. not when it is embedded in a web page.
|
||||
if (!this.viewerPrefs['showPreviousViewOnLoad']) {
|
||||
this.pdfHistory.clearHistoryState();
|
||||
}
|
||||
this.pdfHistory.initialize(this.documentFingerprint);
|
||||
|
||||
if (this.pdfHistory.initialDestination) {
|
||||
this.initialDestination = this.pdfHistory.initialDestination;
|
||||
} else if (this.pdfHistory.initialBookmark) {
|
||||
this.initialBookmark = this.pdfHistory.initialBookmark;
|
||||
}
|
||||
let resetHistory = !this.viewerPrefs['showPreviousViewOnLoad'];
|
||||
this.pdfHistory.initialize(id, resetHistory);
|
||||
}
|
||||
|
||||
let initialParams = {
|
||||
destination: this.initialDestination,
|
||||
bookmark: this.initialBookmark,
|
||||
hash: null,
|
||||
};
|
||||
|
@ -991,14 +981,12 @@ let PDFViewerApplication = {
|
|||
}).then(() => {
|
||||
// For documents with different page sizes, once all pages are resolved,
|
||||
// ensure that the correct location becomes visible on load.
|
||||
if (!initialParams.destination && !initialParams.bookmark &&
|
||||
!initialParams.hash) {
|
||||
if (!initialParams.bookmark && !initialParams.hash) {
|
||||
return;
|
||||
}
|
||||
if (pdfViewer.hasEqualPageSizes) {
|
||||
return;
|
||||
}
|
||||
this.initialDestination = initialParams.destination;
|
||||
this.initialBookmark = initialParams.bookmark;
|
||||
|
||||
pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
|
||||
|
@ -1141,12 +1129,8 @@ let PDFViewerApplication = {
|
|||
this.isInitialViewSet = true;
|
||||
this.pdfSidebar.setInitialView(sidebarView);
|
||||
|
||||
if (this.initialDestination) {
|
||||
this.pdfLinkService.navigateTo(this.initialDestination);
|
||||
this.initialDestination = null;
|
||||
} else if (this.initialBookmark) {
|
||||
if (this.initialBookmark) {
|
||||
this.pdfLinkService.setHash(this.initialBookmark);
|
||||
this.pdfHistory.push({ hash: this.initialBookmark, }, true);
|
||||
this.initialBookmark = null;
|
||||
} else if (storedHash) {
|
||||
this.pdfLinkService.setHash(storedHash);
|
||||
|
@ -1787,10 +1771,6 @@ function webViewerUpdateViewarea(evt) {
|
|||
PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href =
|
||||
href;
|
||||
|
||||
// Update the current bookmark in the browsing history.
|
||||
PDFViewerApplication.pdfHistory.updateCurrentBookmark(location.pdfOpenParams,
|
||||
location.pageNumber);
|
||||
|
||||
// Show/hide the loading indicator in the page number input element.
|
||||
let currentPage =
|
||||
PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
|
||||
|
@ -1814,16 +1794,14 @@ function webViewerResize() {
|
|||
}
|
||||
|
||||
function webViewerHashchange(evt) {
|
||||
if (PDFViewerApplication.pdfHistory.isHashChangeUnlocked) {
|
||||
let hash = evt.hash;
|
||||
if (!hash) {
|
||||
return;
|
||||
}
|
||||
if (!PDFViewerApplication.isInitialViewSet) {
|
||||
PDFViewerApplication.initialBookmark = hash;
|
||||
} else {
|
||||
PDFViewerApplication.pdfLinkService.setHash(hash);
|
||||
}
|
||||
let hash = evt.hash;
|
||||
if (!hash) {
|
||||
return;
|
||||
}
|
||||
if (!PDFViewerApplication.isInitialViewSet) {
|
||||
PDFViewerApplication.initialBookmark = hash;
|
||||
} else {
|
||||
PDFViewerApplication.pdfLinkService.setHash(hash);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2277,23 +2255,6 @@ function webViewerKeyDown(evt) {
|
|||
}
|
||||
}
|
||||
|
||||
if (cmd === 2) { // alt-key
|
||||
switch (evt.keyCode) {
|
||||
case 37: // left arrow
|
||||
if (isViewerInPresentationMode) {
|
||||
PDFViewerApplication.pdfHistory.back();
|
||||
handled = true;
|
||||
}
|
||||
break;
|
||||
case 39: // right arrow
|
||||
if (isViewerInPresentationMode) {
|
||||
PDFViewerApplication.pdfHistory.forward();
|
||||
handled = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
|
||||
// The page container is not focused, but a page navigation key has been
|
||||
// pressed. Change the focus to the viewer container to make sure that
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue