Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor PDFFindController to use the 'pagesinit' event, dispatched on the eventBus, to resolve the _firstPagePromise #9861

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ let PDFViewerApplication = {

this.findController = new PDFFindController({
pdfViewer: this.pdfViewer,
eventBus,
});
this.findController.onUpdateResultsCount = (matchCount) => {
if (this.supportsIntegratedFind) {
Expand Down
4 changes: 0 additions & 4 deletions web/base_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,6 @@ class BaseViewer {
if (this.defaultRenderingQueue) {
this.update();
}

if (this.findController) {
this.findController.resolveFirstPage();
}
}).catch((reason) => {
console.error('Unable to initialize viewer', reason);
});
Expand Down
10 changes: 8 additions & 2 deletions web/pdf_find_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

import { createPromiseCapability } from 'pdfjs-lib';
import { getGlobalEventBus } from './dom_events';
import { scrollIntoView } from './ui_utils';

const FindState = {
Expand Down Expand Up @@ -45,8 +46,9 @@ const CHARACTERS_TO_NORMALIZE = {
* Provides search functionality to find a given string in a PDF document.
*/
class PDFFindController {
constructor({ pdfViewer, }) {
constructor({ pdfViewer, eventBus = getGlobalEventBus(), }) {
this.pdfViewer = pdfViewer;
this.eventBus = eventBus;

this.onUpdateResultsCount = null;
this.onUpdateState = null;
Expand Down Expand Up @@ -82,7 +84,11 @@ class PDFFindController {
this.findTimeout = null;

this._firstPagePromise = new Promise((resolve) => {
this.resolveFirstPage = resolve;
const eventBus = this.eventBus;
eventBus.on('pagesinit', function onPagesInit() {
eventBus.off('pagesinit', onPagesInit);
resolve();
});
});
}

Expand Down