Slightly simplify the PDFFindController._extractText method

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.
This commit is contained in:
Jonas Jenwald 2022-03-19 12:13:29 +01:00
parent 489e9ff7d3
commit cc1bca6268

View File

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