From 4275481e085d875c6ee69cb97d530c240359ebbe Mon Sep 17 00:00:00 2001 From: Fil Zembowicz Date: Wed, 1 Oct 2014 19:57:57 -0400 Subject: [PATCH 1/2] Fix how matches are found in search Instead of keeping track of where the search starts, just keep track of the number of pages and make sure we don't visit pages more than once. --- web/pdf_find_controller.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index 9de1d04a6..1f887e902 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -44,6 +44,7 @@ var PDFFindController = (function PDFFindControllerClosure() { pageIdx: null, matchIdx: null }; + this.pagesToSearch = null; this.resumePageIdx = null; this.state = null; this.dirtyMatch = false; @@ -255,6 +256,8 @@ var PDFFindController = (function PDFFindControllerClosure() { } var offset = this.offset; + // Keep track of how many pages we should maximally iterate through. + this.pagesToSearch = this.pdfViewer.pagesCount; // If there's already a matchIdx that means we are iterating through a // page's matches. if (offset.matchIdx !== null) { @@ -293,8 +296,8 @@ var PDFFindController = (function PDFFindControllerClosure() { this.advanceOffsetPage(previous); if (offset.wrapped) { offset.matchIdx = null; - if (!this.hadMatch) { - // No point in wrapping, there were no matches. + if (this.pagesToSearch < 0) { + // No point in wrapping again, there were no matches. this.updateMatch(false); // while matches were not found, searching for a page // with matches should nevertheless halt. @@ -327,11 +330,12 @@ var PDFFindController = (function PDFFindControllerClosure() { var numPages = this.extractTextPromises.length; offset.pageIdx = (previous ? offset.pageIdx - 1 : offset.pageIdx + 1); offset.matchIdx = null; + + this.pagesToSearch--; if (offset.pageIdx >= numPages || offset.pageIdx < 0) { offset.pageIdx = (previous ? numPages - 1 : 0); offset.wrapped = true; - return; } }, From dcb931dbe018db035346f8f4a1156edadde46a7a Mon Sep 17 00:00:00 2001 From: Fil Zembowicz Date: Thu, 2 Oct 2014 08:57:01 -0400 Subject: [PATCH 2/2] Use existing page count in nextMatch --- web/pdf_find_controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index 1f887e902..1aa912109 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -257,7 +257,7 @@ var PDFFindController = (function PDFFindControllerClosure() { var offset = this.offset; // Keep track of how many pages we should maximally iterate through. - this.pagesToSearch = this.pdfViewer.pagesCount; + this.pagesToSearch = numPages; // If there's already a matchIdx that means we are iterating through a // page's matches. if (offset.matchIdx !== null) {