Add a _updateAllPages
helper method to PDFFindController
in order to reduce the amount of event dispatching
Given that dispatching the 'updatetextlayermatches' event with `pageIndex = -1` set is now used to target the textLayers of *all* pages, there's no need to send individual events to every single page during `_nextMatch`. Since there can be an arbitrary number of pages in a document, this small/simple optimization seems too easy to ignore.
This commit is contained in:
parent
dc98bf76eb
commit
27b21f2558
@ -389,6 +389,13 @@ class PDFFindController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_updateAllPages() {
|
||||||
|
this._eventBus.dispatch('updatetextlayermatches', {
|
||||||
|
source: this,
|
||||||
|
pageIndex: -1,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
_nextMatch() {
|
_nextMatch() {
|
||||||
const previous = this._state.findPrevious;
|
const previous = this._state.findPrevious;
|
||||||
const currentPageIndex = this._linkService.page - 1;
|
const currentPageIndex = this._linkService.page - 1;
|
||||||
@ -407,12 +414,13 @@ class PDFFindController {
|
|||||||
this._pageMatchesLength = null;
|
this._pageMatchesLength = null;
|
||||||
this._matchesCountTotal = 0;
|
this._matchesCountTotal = 0;
|
||||||
|
|
||||||
for (let i = 0; i < numPages; i++) {
|
this._updateAllPages(); // Wipe out any previously highlighted matches.
|
||||||
// Wipe out any previously highlighted matches.
|
|
||||||
this._updatePage(i);
|
|
||||||
|
|
||||||
|
for (let i = 0; i < numPages; i++) {
|
||||||
// Start finding the matches as soon as the text is extracted.
|
// Start finding the matches as soon as the text is extracted.
|
||||||
if (!(i in this._pendingFindMatches)) {
|
if (this._pendingFindMatches[i] === true) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
this._pendingFindMatches[i] = true;
|
this._pendingFindMatches[i] = true;
|
||||||
this._extractTextPromises[i].then((pageIdx) => {
|
this._extractTextPromises[i].then((pageIdx) => {
|
||||||
delete this._pendingFindMatches[pageIdx];
|
delete this._pendingFindMatches[pageIdx];
|
||||||
@ -420,7 +428,6 @@ class PDFFindController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If there's no query there's no point in searching.
|
// If there's no query there's no point in searching.
|
||||||
if (this._state.query === '') {
|
if (this._state.query === '') {
|
||||||
@ -557,11 +564,7 @@ class PDFFindController {
|
|||||||
this._updateUIState(FindState.FOUND);
|
this._updateUIState(FindState.FOUND);
|
||||||
}
|
}
|
||||||
this._highlightMatches = false;
|
this._highlightMatches = false;
|
||||||
|
this._updateAllPages(); // Wipe out any previously highlighted matches.
|
||||||
this._eventBus.dispatch('updatetextlayermatches', {
|
|
||||||
source: this,
|
|
||||||
pageIndex: -1,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user