diff --git a/web/app.js b/web/app.js index 63e7142a2..62b65b157 100644 --- a/web/app.js +++ b/web/app.js @@ -346,25 +346,6 @@ let PDFViewerApplication = { linkService: pdfLinkService, eventBus, }); - this.findController.onUpdateResultsCount = (matchesCount) => { - if (this.supportsIntegratedFind) { - this.externalServices.updateFindMatchesCount(matchesCount); - } else { - this.findBar.updateResultsCount(matchesCount); - } - }; - this.findController.onUpdateState = (state, previous, matchesCount) => { - if (this.supportsIntegratedFind) { - this.externalServices.updateFindControlState({ - result: state, - findPrevious: previous, - matchesCount, - }); - } else { - this.findBar.updateUIState(state, previous, matchesCount); - } - }; - this.pdfViewer.setFindController(this.findController); // TODO: improve `PDFFindBar` constructor parameter passing @@ -1343,6 +1324,8 @@ let PDFViewerApplication = { eventBus.on('documentproperties', webViewerDocumentProperties); eventBus.on('find', webViewerFind); eventBus.on('findfromurlhash', webViewerFindFromUrlHash); + eventBus.on('updatefindmatchescount', webViewerUpdateFindMatchesCount); + eventBus.on('updatefindcontrolstate', webViewerUpdateFindControlState); if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { eventBus.on('fileinputchange', webViewerFileInputChange); } @@ -1414,6 +1397,8 @@ let PDFViewerApplication = { eventBus.off('documentproperties', webViewerDocumentProperties); eventBus.off('find', webViewerFind); eventBus.off('findfromurlhash', webViewerFindFromUrlHash); + eventBus.off('updatefindmatchescount', webViewerUpdateFindMatchesCount); + eventBus.off('updatefindcontrolstate', webViewerUpdateFindControlState); if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { eventBus.off('fileinputchange', webViewerFileInputChange); } @@ -1976,6 +1961,26 @@ function webViewerFindFromUrlHash(evt) { }); } +function webViewerUpdateFindMatchesCount({ matchesCount, }) { + if (PDFViewerApplication.supportsIntegratedFind) { + PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount); + } else { + PDFViewerApplication.findBar.updateResultsCount(matchesCount); + } +} + +function webViewerUpdateFindControlState({ state, previous, matchesCount, }) { + if (PDFViewerApplication.supportsIntegratedFind) { + PDFViewerApplication.externalServices.updateFindControlState({ + result: state, + findPrevious: previous, + matchesCount, + }); + } else { + PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount); + } +} + function webViewerScaleChanging(evt) { PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale); diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index 082eb6a63..a74df0893 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -57,9 +57,6 @@ class PDFFindController { this._linkService = linkService; this._eventBus = eventBus; - this.onUpdateResultsCount = null; - this.onUpdateState = null; - this._reset(); eventBus.on('findbarclose', () => { @@ -564,19 +561,19 @@ class PDFFindController { } _updateUIResultsCount() { - if (!this.onUpdateResultsCount) { - return; - } - const matchesCount = this._requestMatchesCount(); - this.onUpdateResultsCount(matchesCount); + this._eventBus.dispatch('updatefindmatchescount', { + source: this, + matchesCount: this._requestMatchesCount(), + }); } _updateUIState(state, previous) { - if (!this.onUpdateState) { - return; - } - const matchesCount = this._requestMatchesCount(); - this.onUpdateState(state, previous, matchesCount); + this._eventBus.dispatch('updatefindcontrolstate', { + source: this, + state, + previous, + matchesCount: this._requestMatchesCount(), + }); } }