Skip to content

Commit 54dfe05

Browse files
JonasJonas
authored andcommitted
Prevent searching during load from breaking the find functionality
1 parent c5bcd7a commit 54dfe05

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

web/pdf_find_controller.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ var PDFFindController = {
6464

6565
integratedFind: false,
6666

67+
firstPagePromise: new PDFJS.Promise(),
68+
6769
initialize: function(options) {
6870
if(typeof PDFFindBar === 'undefined' || PDFFindBar === null) {
6971
throw 'PDFFindController cannot be initialized ' +
@@ -172,15 +174,17 @@ var PDFFindController = {
172174
this.state = e.detail;
173175
this.updateUIState(FindStates.FIND_PENDING);
174176

175-
this.extractText();
177+
this.firstPagePromise.then(function() {
178+
this.extractText();
176179

177-
clearTimeout(this.findTimeout);
178-
if (e.type === 'find') {
179-
// Only trigger the find action after 250ms of silence.
180-
this.findTimeout = setTimeout(this.nextMatch.bind(this), 250);
181-
} else {
182-
this.nextMatch();
183-
}
180+
clearTimeout(this.findTimeout);
181+
if (e.type === 'find') {
182+
// Only trigger the find action after 250ms of silence.
183+
this.findTimeout = setTimeout(this.nextMatch.bind(this), 250);
184+
} else {
185+
this.nextMatch();
186+
}
187+
}.bind(this));
184188
},
185189

186190
updatePage: function(idx) {

web/viewer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,6 @@ var Settings = (function SettingsClosure() {
162162
var cache = new Cache(CACHE_SIZE);
163163
var currentPageNumber = 1;
164164

165-
// TODO: Enable the FindBar *AFTER* the pagesPromise in the load function
166-
// got resolved
167165
//#include pdf_find_bar.js
168166
//#include pdf_find_controller.js
169167
//#include pdf_history.js
@@ -941,6 +939,8 @@ var PDFView = {
941939
pagePromises.push(pagePromise);
942940
}
943941

942+
PDFFindController.firstPagePromise.resolve();
943+
944944
PDFJS.Promise.all(pagePromises).then(function(pages) {
945945
pagesPromise.resolve(pages);
946946
});

0 commit comments

Comments
 (0)