Browse Source

Fixes a minor find bugs.

Brendan Dahl 13 years ago
parent
commit
a829b06d20
  1. 30
      web/viewer.js

30
web/viewer.js

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

Loading…
Cancel
Save