Also update the browser history when the user *manually* change pages using the pageNumber-input (PR 12493 follow-up)

This patch addresses a review comment, which pointed out that we should *also* handle the pageNumber-input, from PR 12493.

Given that a user *manually* changing pages using the pageNumber-input, on the toolbar, could be regarded as a pretty strong indication of user-intent w.r.t. navigation in the document, hence I suppose that updating the browser history in this case as well probably won't hurt.
This commit is contained in:
Jonas Jenwald 2020-10-31 10:17:28 +01:00
parent 4eaa058c16
commit 911948c5c0
4 changed files with 27 additions and 10 deletions

View File

@ -2537,7 +2537,7 @@ function webViewerPageNumberChanged(evt) {
// Note that for `<input type="number">` HTML elements, an empty string will // Note that for `<input type="number">` HTML elements, an empty string will
// be returned for non-number inputs; hence we simply do nothing in that case. // be returned for non-number inputs; hence we simply do nothing in that case.
if (evt.value !== "") { if (evt.value !== "") {
pdfViewer.currentPageLabel = evt.value; PDFViewerApplication.pdfLinkService.goToPage(evt.value);
} }
// Ensure that the page number input displays the correct value, even if the // Ensure that the page number input displays the correct value, even if the

View File

@ -787,6 +787,22 @@ class BaseViewer {
this._scrollIntoView({ pageDiv: pageView.div }); this._scrollIntoView({ pageDiv: pageView.div });
} }
/**
* @param {string} label - The page label.
* @returns {number|null} The page number corresponding to the page label,
* or `null` when no page labels exist and/or the input is invalid.
*/
pageLabelToPageNumber(label) {
if (!this._pageLabels) {
return null;
}
const i = this._pageLabels.indexOf(label);
if (i < 0) {
return null;
}
return i + 1;
}
/** /**
* @typedef ScrollPageIntoViewParameters * @typedef ScrollPageIntoViewParameters
* @property {number} pageNumber - The page number. * @property {number} pageNumber - The page number.

View File

@ -59,9 +59,9 @@ class IPDFLinkService {
async goToDestination(dest) {} async goToDestination(dest) {}
/** /**
* @param {number} pageNumber - The page number. * @param {number|string} val - The page number, or page label.
*/ */
goToPage(pageNumber) {} goToPage(val) {}
/** /**
* @param dest - The PDF destination object. * @param dest - The PDF destination object.

View File

@ -206,12 +206,15 @@ class PDFLinkService {
/** /**
* This method will, when available, also update the browser history. * This method will, when available, also update the browser history.
* *
* @param {number} pageNumber - The page number. * @param {number|string} val - The page number, or page label.
*/ */
goToPage(pageNumber) { goToPage(val) {
if (!this.pdfDocument) { if (!this.pdfDocument) {
return; return;
} }
const pageNumber =
(typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val)) ||
val | 0;
if ( if (
!( !(
Number.isInteger(pageNumber) && Number.isInteger(pageNumber) &&
@ -219,9 +222,7 @@ class PDFLinkService {
pageNumber <= this.pagesCount pageNumber <= this.pagesCount
) )
) { ) {
console.error( console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
`PDFLinkService.goToPage: "${pageNumber}" is not a valid page number.`
);
return; return;
} }
@ -566,9 +567,9 @@ class SimpleLinkService {
async goToDestination(dest) {} async goToDestination(dest) {}
/** /**
* @param {number} pageNumber - The page number. * @param {number|string} val - The page number, or page label.
*/ */
goToPage(pageNumber) {} goToPage(val) {}
/** /**
* @param dest - The PDF destination object. * @param dest - The PDF destination object.