Fixes a minor find bugs.

This commit is contained in:
Brendan Dahl 2012-10-05 12:21:04 -07:00
parent c28ef14403
commit a829b06d20

View File

@ -229,7 +229,7 @@ var cache = new Cache(kCacheSize);
var currentPageNumber = 1;
var PDFFindController = {
startedTextExtraction: false,
extractTextPromise: null,
// If active, find results will be highlighted.
active: false,
@ -244,6 +244,8 @@ var PDFFindController = {
matchIdx: 0
},
state: null,
dirtyMatch: false,
findTimeout: null,
@ -291,9 +293,11 @@ var PDFFindController = {
},
extractText: function() {
if (this.startedTextExtraction)
return;
this.startedTextExtraction = true;
if (this.extractTextPromise) {
return this.extractTextPromise;
}
this.extractTextPromise = new PDFJS.Promise();
var self = this;
function extractPageText(pageIndex) {
PDFView.pages[pageIndex].getTextContent().then(
@ -313,24 +317,32 @@ var PDFFindController = {
if ((pageIndex + 1) < PDFView.pages.length)
extractPageText(pageIndex + 1);
else
self.extractTextPromise.resolve();
}
);
}
extractPageText(0);
return this.extractTextPromise;
},
handleEvent: function(e) {
this.state = e.detail;
if (e.detail.findPrevious === undefined) {
if (this.state === null || e.type !== 'findagain') {
this.dirtyMatch = true;
}
this.state = e.detail;
this.updateUIState(FindStates.FIND_PENDING);
var promise = this.extractText();
clearTimeout(this.findTimeout);
if (e.type === 'find') {
// Only trigger the find action after 250ms of silence.
this.findTimeout = setTimeout(this.performFind.bind(this), 250);
this.findTimeout = setTimeout(function() {
promise.then(this.performFind.bind(this));
}.bind(this), 250);
} else {
this.performFind();
promise.then(this.performFind.bind(this));
}
},
@ -359,8 +371,6 @@ var PDFFindController = {
this.active = true;
this.updateUIState(FindStates.FIND_PENDING);
if (this.dirtyMatch) {
// Need to recalculate the matches.
this.dirtyMatch = false;