Merge pull request #11880 from Snuffleupagus/issue-11875

Attempt to respect the "zoom" hash parameter, even when the "nameddest" parameter is present (issue 11875)
This commit is contained in:
Tim van der Meij 2020-05-08 23:42:12 +02:00 committed by GitHub
commit 7823d593f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 8 deletions

View File

@ -117,7 +117,9 @@ class PDFHistory {
this._position = null; this._position = null;
if (!this._isValidState(state, /* checkReload = */ true) || resetHistory) { if (!this._isValidState(state, /* checkReload = */ true) || resetHistory) {
const { hash, page, rotation } = this._parseCurrentHash(); const { hash, page, rotation } = this._parseCurrentHash(
/* checkNameddest = */ true
);
if (!hash || reInitialized || resetHistory) { if (!hash || reInitialized || resetHistory) {
// Ensure that the browser history is reset on PDF document load. // Ensure that the browser history is reset on PDF document load.
@ -490,16 +492,20 @@ class PDFHistory {
/** /**
* @private * @private
*/ */
_parseCurrentHash() { _parseCurrentHash(checkNameddest = false) {
const hash = unescape(getCurrentHash()).substring(1); const hash = unescape(getCurrentHash()).substring(1);
let page = parseQueryString(hash).page | 0; const params = parseQueryString(hash);
const nameddest = params.nameddest || "";
let page = params.page | 0;
if ( if (
!( !(
Number.isInteger(page) && Number.isInteger(page) &&
page > 0 && page > 0 &&
page <= this.linkService.pagesCount page <= this.linkService.pagesCount
) ) ||
(checkNameddest && nameddest.length > 0)
) { ) {
page = null; page = null;
} }

View File

@ -233,10 +233,6 @@ class PDFLinkService {
}); });
} }
// borrowing syntax from "Parameters for Opening PDF Files" // borrowing syntax from "Parameters for Opening PDF Files"
if ("nameddest" in params) {
this.navigateTo(params.nameddest);
return;
}
if ("page" in params) { if ("page" in params) {
pageNumber = params.page | 0 || 1; pageNumber = params.page | 0 || 1;
} }
@ -308,6 +304,11 @@ class PDFLinkService {
mode: params.pagemode, mode: params.pagemode,
}); });
} }
// Ensure that this parameter is *always* handled last, in order to
// guarantee that it won't be overridden (e.g. by the "page" parameter).
if ("nameddest" in params) {
this.navigateTo(params.nameddest);
}
} else { } else {
// Named (or explicit) destination. // Named (or explicit) destination.
dest = unescape(hash); dest = unescape(hash);