Merge pull request #16479 from Snuffleupagus/PDFFindController-onIsPageVisible
Re-factor the `isPageVisible`-handling in the find-controller (PR 10217 follow-up)
This commit is contained in:
commit
6d8810b55c
@ -113,11 +113,6 @@ class IPDFLinkService {
|
|||||||
*/
|
*/
|
||||||
cachePageRef(pageNum, pageRef) {}
|
cachePageRef(pageNum, pageRef) {}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {number} pageNumber
|
|
||||||
*/
|
|
||||||
isPageVisible(pageNumber) {}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} pageNumber
|
* @param {number} pageNumber
|
||||||
*/
|
*/
|
||||||
|
@ -396,6 +396,12 @@ class PDFFindController {
|
|||||||
this._eventBus = eventBus;
|
this._eventBus = eventBus;
|
||||||
this.#updateMatchesCountOnProgress = updateMatchesCountOnProgress;
|
this.#updateMatchesCountOnProgress = updateMatchesCountOnProgress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback used to check if a `pageNumber` is currently visible.
|
||||||
|
* @type {function}
|
||||||
|
*/
|
||||||
|
this.onIsPageVisible = null;
|
||||||
|
|
||||||
this.#reset();
|
this.#reset();
|
||||||
eventBus._on("find", this.#onFind.bind(this));
|
eventBus._on("find", this.#onFind.bind(this));
|
||||||
eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
|
eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
|
||||||
@ -636,15 +642,12 @@ class PDFFindController {
|
|||||||
// there's a risk that consecutive 'findagain' operations could "skip"
|
// there's a risk that consecutive 'findagain' operations could "skip"
|
||||||
// over matches at the top/bottom of pages thus making them completely
|
// over matches at the top/bottom of pages thus making them completely
|
||||||
// inaccessible when there's multiple pages visible in the viewer.
|
// inaccessible when there's multiple pages visible in the viewer.
|
||||||
if (
|
return (
|
||||||
pageNumber >= 1 &&
|
pageNumber >= 1 &&
|
||||||
pageNumber <= linkService.pagesCount &&
|
pageNumber <= linkService.pagesCount &&
|
||||||
pageNumber !== linkService.page &&
|
pageNumber !== linkService.page &&
|
||||||
!linkService.isPageVisible(pageNumber)
|
!(this.onIsPageVisible?.(pageNumber) ?? true)
|
||||||
) {
|
);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
case "highlightallchange":
|
case "highlightallchange":
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -569,13 +569,6 @@ class PDFLinkService {
|
|||||||
return this.#pagesRefCache.get(refStr) || null;
|
return this.#pagesRefCache.get(refStr) || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {number} pageNumber
|
|
||||||
*/
|
|
||||||
isPageVisible(pageNumber) {
|
|
||||||
return this.pdfViewer.isPageVisible(pageNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} pageNumber
|
* @param {number} pageNumber
|
||||||
*/
|
*/
|
||||||
@ -745,13 +738,6 @@ class SimpleLinkService {
|
|||||||
*/
|
*/
|
||||||
cachePageRef(pageNum, pageRef) {}
|
cachePageRef(pageNum, pageRef) {}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {number} pageNumber
|
|
||||||
*/
|
|
||||||
isPageVisible(pageNumber) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} pageNumber
|
* @param {number} pageNumber
|
||||||
*/
|
*/
|
||||||
|
@ -259,6 +259,11 @@ class PDFViewer {
|
|||||||
this.linkService = options.linkService || new SimpleLinkService();
|
this.linkService = options.linkService || new SimpleLinkService();
|
||||||
this.downloadManager = options.downloadManager || null;
|
this.downloadManager = options.downloadManager || null;
|
||||||
this.findController = options.findController || null;
|
this.findController = options.findController || null;
|
||||||
|
|
||||||
|
if (this.findController) {
|
||||||
|
this.findController.onIsPageVisible = pageNumber =>
|
||||||
|
this._getVisiblePages().ids.has(pageNumber);
|
||||||
|
}
|
||||||
this._scriptingManager = options.scriptingManager || null;
|
this._scriptingManager = options.scriptingManager || null;
|
||||||
this.#textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE;
|
this.#textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE;
|
||||||
this.#annotationMode =
|
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
|
* @param {number} pageNumber
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user