Ensure that we don't reset the current page view if the user inputs an invalid page number (PR 7289 follow-up)
After PR 7289, we'll now reset the current page view in cases where I don't think we should. To avoid this, this patch ensures that we'll not modify the position when the page number is out-of-bounds. **STR:** 1. Open http://mozilla.github.io/pdf.js/web/viewer.html#page=1&zoom=auto,-98,696 2. Enter an invalid number, e.g. `1000`, in the `pageNumber` input. **ER:** The current position in the document shouldn't change, since the page number wasn't valid. **AR:** The document resets to the top of the page `1`.
This commit is contained in:
parent
1695893526
commit
9f34700e0d
@ -155,22 +155,34 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
return this._pages[index];
|
return this._pages[index];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
get currentPageNumber() {
|
get currentPageNumber() {
|
||||||
return this._currentPageNumber;
|
return this._currentPageNumber;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} val - The page number.
|
||||||
|
*/
|
||||||
set currentPageNumber(val) {
|
set currentPageNumber(val) {
|
||||||
if (!this.pdfDocument) {
|
if (!this.pdfDocument) {
|
||||||
this._currentPageNumber = val;
|
this._currentPageNumber = val;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._setCurrentPageNumber(val);
|
|
||||||
// The intent can be to just reset a scroll position and/or scale.
|
// The intent can be to just reset a scroll position and/or scale.
|
||||||
this._resetCurrentPageView();
|
this._setCurrentPageNumber(val, /* resetCurrentPageView = */ true);
|
||||||
},
|
},
|
||||||
|
|
||||||
_setCurrentPageNumber: function pdfViewer_setCurrentPageNumber(val) {
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_setCurrentPageNumber:
|
||||||
|
function pdfViewer_setCurrentPageNumber(val, resetCurrentPageView) {
|
||||||
if (this._currentPageNumber === val) {
|
if (this._currentPageNumber === val) {
|
||||||
|
if (resetCurrentPageView) {
|
||||||
|
this._resetCurrentPageView();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var arg;
|
var arg;
|
||||||
@ -193,6 +205,10 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
this._currentPageNumber = val;
|
this._currentPageNumber = val;
|
||||||
this.eventBus.dispatch('pagechanging', arg);
|
this.eventBus.dispatch('pagechanging', arg);
|
||||||
this.eventBus.dispatch('pagechange', arg);
|
this.eventBus.dispatch('pagechange', arg);
|
||||||
|
|
||||||
|
if (resetCurrentPageView) {
|
||||||
|
this._resetCurrentPageView();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -500,6 +516,7 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Refreshes page view: scrolls to the current page and updates the scale.
|
* Refreshes page view: scrolls to the current page and updates the scale.
|
||||||
|
* @private
|
||||||
*/
|
*/
|
||||||
_resetCurrentPageView: function () {
|
_resetCurrentPageView: function () {
|
||||||
if (this.isInPresentationMode) {
|
if (this.isInPresentationMode) {
|
||||||
@ -524,8 +541,7 @@ var PDFViewer = (function pdfViewer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.isInPresentationMode || !dest) {
|
if (this.isInPresentationMode || !dest) {
|
||||||
this._setCurrentPageNumber(pageNumber);
|
this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView */ true);
|
||||||
this._resetCurrentPageView();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user