Skip to content

Commit

Permalink
Don't block page rendering while search is in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtcode committed Nov 5, 2024
1 parent 0f1cd53 commit 7184222
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/pdf/pdf-find-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1002,16 +1002,22 @@ class PDFFindController {
return;
}

let resolvers = [];
for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
const { promise, resolve } = Promise.withResolvers();
this._extractTextPromises[i] = promise;
resolvers.push(resolve);
}

(async () => {
(async () => {
for (let i = 0; i < resolvers.length; i++) {
let resolve = resolvers[i];

let text = '';
let chars = [];

try {
await new Promise(resolve => setTimeout(resolve));
let pageData = await this._pdfDocument.getPageData({ pageIndex: i });

function getTextFromChars(chars) {
Expand All @@ -1027,7 +1033,8 @@ class PDFFindController {

chars = pageData.chars;
text = getTextFromChars(pageData.chars);
} catch (e) {
}
catch (e) {
console.log(e);
}

Expand All @@ -1041,8 +1048,8 @@ class PDFFindController {
] = normalize(text);

resolve();
})();
}
}
})();
}

_nextMatch() {
Expand Down

0 comments on commit 7184222

Please sign in to comment.