Re-factor the isPageVisible-handling in the find-controller (PR 10217 follow-up)

The way that this was implemented in PR 10217 has always bothered me slightly, since the `isPageVisible`-method that I introduced there always felt quite out-of-place in the `IPDFLinkService`-implementations.
Hence this is instead replaced by a callback-function in `PDFFindController`, to handle the page-visibility checks. Note that since the `PDFViewer`-constructor always sets this callback-function, e.g. the viewer-component examples still work as-is.
This commit is contained in:
Jonas Jenwald 2023-05-26 10:31:54 +02:00
parent cbc4b20b12
commit d0bf505312
4 changed files with 14 additions and 45 deletions

View file

@ -259,6 +259,11 @@ class PDFViewer {
this.linkService = options.linkService || new SimpleLinkService();
this.downloadManager = options.downloadManager || null;
this.findController = options.findController || null;
if (this.findController) {
this.findController.onIsPageVisible = pageNumber =>
this._getVisiblePages().ids.has(pageNumber);
}
this._scriptingManager = options.scriptingManager || null;
this.#textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE;
this.#annotationMode =
@ -1640,26 +1645,6 @@ class PDFViewer {
});
}
/**
* @param {number} pageNumber
*/
isPageVisible(pageNumber) {
if (!this.pdfDocument) {
return false;
}
if (
!(
Number.isInteger(pageNumber) &&
pageNumber > 0 &&
pageNumber <= this.pagesCount
)
) {
console.error(`isPageVisible: "${pageNumber}" is not a valid page.`);
return false;
}
return this._getVisiblePages().ids.has(pageNumber);
}
/**
* @param {number} pageNumber
*/