Merge pull request #10060 from Snuffleupagus/matchesCount-invalid

Ensure that `PDFFindController._requestMatchesCount` won't return broken data when searching starts (PR 10052 follow-up)
This commit is contained in:
Tim van der Meij 2018-09-11 15:40:41 +02:00 committed by GitHub
commit a789368b7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -510,14 +510,20 @@ class PDFFindController {
_requestMatchesCount() {
const { pageIdx, matchIdx, } = this.selected;
let current = 0;
let current = 0, total = this.matchesCountTotal;
if (matchIdx !== -1) {
for (let i = 0; i < pageIdx; i++) {
current += (this.pageMatches[i] && this.pageMatches[i].length) || 0;
}
current += matchIdx + 1;
}
return { current, total: this.matchesCountTotal, };
// When searching starts, this method may be called before the `pageMatches`
// have been counted (in `_calculateMatch`). Ensure that the UI won't show
// temporarily broken state when the active find result doesn't make sense.
if (current > total) {
current = total = 0;
}
return { current, total, };
}
_updateUIResultsCount() {