Merge pull request #9861 from Snuffleupagus/PDFFindController-firstPagePromise

Refactor `PDFFindController` to use the 'pagesinit' event, dispatched on the `eventBus`, to resolve the `_firstPagePromise`
This commit is contained in:
Tim van der Meij 2018-07-02 23:30:37 +02:00 committed by GitHub
commit 42922c9ae5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions

View File

@ -409,6 +409,7 @@ let PDFViewerApplication = {
this.findController = new PDFFindController({ this.findController = new PDFFindController({
pdfViewer: this.pdfViewer, pdfViewer: this.pdfViewer,
eventBus,
}); });
this.findController.onUpdateResultsCount = (matchCount) => { this.findController.onUpdateResultsCount = (matchCount) => {
if (this.supportsIntegratedFind) { if (this.supportsIntegratedFind) {

View File

@ -479,10 +479,6 @@ class BaseViewer {
if (this.defaultRenderingQueue) { if (this.defaultRenderingQueue) {
this.update(); this.update();
} }
if (this.findController) {
this.findController.resolveFirstPage();
}
}).catch((reason) => { }).catch((reason) => {
console.error('Unable to initialize viewer', reason); console.error('Unable to initialize viewer', reason);
}); });

View File

@ -14,6 +14,7 @@
*/ */
import { createPromiseCapability } from 'pdfjs-lib'; import { createPromiseCapability } from 'pdfjs-lib';
import { getGlobalEventBus } from './dom_events';
import { scrollIntoView } from './ui_utils'; import { scrollIntoView } from './ui_utils';
const FindState = { const FindState = {
@ -45,8 +46,9 @@ const CHARACTERS_TO_NORMALIZE = {
* Provides search functionality to find a given string in a PDF document. * Provides search functionality to find a given string in a PDF document.
*/ */
class PDFFindController { class PDFFindController {
constructor({ pdfViewer, }) { constructor({ pdfViewer, eventBus = getGlobalEventBus(), }) {
this.pdfViewer = pdfViewer; this.pdfViewer = pdfViewer;
this.eventBus = eventBus;
this.onUpdateResultsCount = null; this.onUpdateResultsCount = null;
this.onUpdateState = null; this.onUpdateState = null;
@ -82,7 +84,11 @@ class PDFFindController {
this.findTimeout = null; this.findTimeout = null;
this._firstPagePromise = new Promise((resolve) => { this._firstPagePromise = new Promise((resolve) => {
this.resolveFirstPage = resolve; const eventBus = this.eventBus;
eventBus.on('pagesinit', function onPagesInit() {
eventBus.off('pagesinit', onPagesInit);
resolve();
});
}); });
} }