From af99d1dc08a535dbecaed8bb465a89ad907d8e26 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 30 Oct 2018 11:08:03 +0100 Subject: [PATCH] Attempt to improve readability of `PDFFindController.executeCommand` by (slightly) refactoring the code responsible for calling `PDFFindController._nextMatch` Unfortunately the `PDFFindController.executeCommand` method has now become a bit more complicated than one would like, but hopefully this small change will improve the structure somewhat (especially for subsequent patches). --- web/pdf_find_controller.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index 624017844..2411a9705 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -128,6 +128,8 @@ class PDFFindController { } this._extractText(); + const findbarClosed = !this._highlightMatches; + if (this._findTimeout) { clearTimeout(this._findTimeout); this._findTimeout = null; @@ -139,14 +141,16 @@ class PDFFindController { this._nextMatch(); this._findTimeout = null; }, FIND_TIMEOUT); - } else if (cmd === 'findagain' && !this._dirtyMatch) { - const updateHighlightAll = (!this._highlightMatches && - this._state.highlightAll); + } else if (this._dirtyMatch) { + // Immediately trigger searching for non-'find' operations, when the + // current state needs to be reset and matches re-calculated. + this._nextMatch(); + } else if (cmd === 'findagain') { this._nextMatch(); // When the findbar was previously closed, and `highlightAll` is set, // ensure that the matches on all active pages are highlighted again. - if (updateHighlightAll) { + if (findbarClosed && this._state.highlightAll) { this._updateAllPages(); } } else {