From 014b7a31476230aed5d0af4cb3b318903c0df184 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 31 Oct 2018 15:54:10 +0100 Subject: [PATCH] Reduce the number of redundant `updatetextlayermatches` events dispatched when calculating matches in `PDFFindController` Currently `PDFFindController._calculateMatch` is (indirectly) dispatching an `updatetextlayermatches` event for every *single* page of the document. For short documents, such as the `tracemonkey` file, this probably doesn't matter too much, but for documents with a couple of thousand pages it seems unfortunate. It shouldn't be necessary, in general, to dispatch `updatetextlayermatches` events here, since that's already being taken care of in `PDFFindController._updateMatch` which is always called when a match has been found. However, when `highlightAll` is set we still need to ensure that pages which finished rendered *before* searching begun are updated correctly. --- web/pdf_find_controller.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index a8f60a1fb..2202a4b47 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -345,7 +345,11 @@ class PDFFindController { this._calculateWordMatch(query, pageIndex, pageContent, entireWord); } - this._updatePage(pageIndex); + // When `highlightAll` is set, ensure that the matches on previously + // rendered (and still active) pages are correctly highlighted. + if (this._state.highlightAll) { + this._updatePage(pageIndex); + } if (this._resumePageIdx === pageIndex) { this._resumePageIdx = null; this._nextPageMatch();