mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
[GV] Add an option in the find controller to update matches count only when the last page is reached (bug 1803188).
In GeckoView, on an event, a callback must be executed with the result of an action, but the callback can be used only one time. So for each FindInPage event, we must trigger only one matches count update.
This commit is contained in:
parent
8a0ca04399
commit
661f425934
3 changed files with 58 additions and 4 deletions
|
@ -458,6 +458,8 @@ const PDFViewerApplication = {
|
|||
const findController = new PDFFindController({
|
||||
linkService: pdfLinkService,
|
||||
eventBus,
|
||||
updateMatchesCountOnProgress:
|
||||
typeof PDFJSDev === "undefined" || !PDFJSDev.test("GECKOVIEW"),
|
||||
});
|
||||
this.findController = findController;
|
||||
|
||||
|
|
|
@ -339,18 +339,26 @@ function getOriginalIndex(diffs, pos, len) {
|
|||
* @typedef {Object} PDFFindControllerOptions
|
||||
* @property {IPDFLinkService} linkService - The navigation/linking service.
|
||||
* @property {EventBus} eventBus - The application event bus.
|
||||
* @property {boolean} updateMatchesCountOnProgress - True if the matches
|
||||
* count must be updated on progress or only when the last page is reached.
|
||||
* The default value is `true`.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides search functionality to find a given string in a PDF document.
|
||||
*/
|
||||
class PDFFindController {
|
||||
#updateMatchesCountOnProgress = true;
|
||||
|
||||
#visitedPagesCount = 0;
|
||||
|
||||
/**
|
||||
* @param {PDFFindControllerOptions} options
|
||||
*/
|
||||
constructor({ linkService, eventBus }) {
|
||||
constructor({ linkService, eventBus, updateMatchesCountOnProgress = true }) {
|
||||
this._linkService = linkService;
|
||||
this._eventBus = eventBus;
|
||||
this.#updateMatchesCountOnProgress = updateMatchesCountOnProgress;
|
||||
|
||||
this.#reset();
|
||||
eventBus._on("find", this.#onFind.bind(this));
|
||||
|
@ -489,6 +497,7 @@ class PDFFindController {
|
|||
this._pdfDocument = null;
|
||||
this._pageMatches = [];
|
||||
this._pageMatchesLength = [];
|
||||
this.#visitedPagesCount = 0;
|
||||
this._state = null;
|
||||
// Currently selected match.
|
||||
this._selected = {
|
||||
|
@ -742,8 +751,14 @@ class PDFFindController {
|
|||
|
||||
// Update the match count.
|
||||
const pageMatchesCount = this._pageMatches[pageIndex].length;
|
||||
if (pageMatchesCount > 0) {
|
||||
this._matchesCountTotal += pageMatchesCount;
|
||||
this._matchesCountTotal += pageMatchesCount;
|
||||
if (this.#updateMatchesCountOnProgress) {
|
||||
if (pageMatchesCount > 0) {
|
||||
this.#updateUIResultsCount();
|
||||
}
|
||||
} else if (++this.#visitedPagesCount === this._linkService.pagesCount) {
|
||||
// For example, in GeckoView we want to have only the final update because
|
||||
// the Java side provides only one object to update the counts.
|
||||
this.#updateUIResultsCount();
|
||||
}
|
||||
}
|
||||
|
@ -838,6 +853,7 @@ class PDFFindController {
|
|||
this._resumePageIdx = null;
|
||||
this._pageMatches.length = 0;
|
||||
this._pageMatchesLength.length = 0;
|
||||
this.#visitedPagesCount = 0;
|
||||
this._matchesCountTotal = 0;
|
||||
|
||||
this.#updateAllPages(); // Wipe out any previously highlighted matches.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue