Skip to content

Commit

Permalink
Slightly simplify the PDFFindController._extractText method
Browse files Browse the repository at this point in the history
Currently we're resolving the Promises in the `_extractTextPromises` Array with the page-index, despite that not really being necessary since the Promises in the Array are explicitly inserted in the correct order.
Furthermore, we can replace the standard `for`-loop with a `for...of`-loop which results in ever so slightly more compact code.
  • Loading branch information
Snuffleupagus committed Mar 19, 2022
1 parent 489e9ff commit cc1bca6
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions web/pdf_find_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,12 +669,11 @@ class PDFFindController {
})
.then(
textContent => {
const textItems = textContent.items;
const strBuf = [];

for (let j = 0, jj = textItems.length; j < jj; j++) {
strBuf.push(textItems[j].str);
if (textItems[j].hasEOL) {
for (const textItem of textContent.items) {
strBuf.push(textItem.str);
if (textItem.hasEOL) {
strBuf.push("\n");
}
}
Expand All @@ -685,7 +684,7 @@ class PDFFindController {
this._pageDiffs[i],
this._hasDiacritics[i],
] = normalize(strBuf.join(""));
extractTextCapability.resolve(i);
extractTextCapability.resolve();
},
reason => {
console.error(
Expand All @@ -696,7 +695,7 @@ class PDFFindController {
this._pageContents[i] = "";
this._pageDiffs[i] = null;
this._hasDiacritics[i] = false;
extractTextCapability.resolve(i);
extractTextCapability.resolve();
}
);
});
Expand Down Expand Up @@ -751,9 +750,9 @@ class PDFFindController {
continue;
}
this._pendingFindMatches.add(i);
this._extractTextPromises[i].then(pageIdx => {
this._pendingFindMatches.delete(pageIdx);
this._calculateMatch(pageIdx);
this._extractTextPromises[i].then(() => {
this._pendingFindMatches.delete(i);
this._calculateMatch(i);
});
}
}
Expand Down

0 comments on commit cc1bca6

Please sign in to comment.