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).
This commit is contained in:
Jonas Jenwald 2018-10-30 11:08:03 +01:00
parent ec76aa531e
commit af99d1dc08

View File

@ -128,6 +128,8 @@ class PDFFindController {
} }
this._extractText(); this._extractText();
const findbarClosed = !this._highlightMatches;
if (this._findTimeout) { if (this._findTimeout) {
clearTimeout(this._findTimeout); clearTimeout(this._findTimeout);
this._findTimeout = null; this._findTimeout = null;
@ -139,14 +141,16 @@ class PDFFindController {
this._nextMatch(); this._nextMatch();
this._findTimeout = null; this._findTimeout = null;
}, FIND_TIMEOUT); }, FIND_TIMEOUT);
} else if (cmd === 'findagain' && !this._dirtyMatch) { } else if (this._dirtyMatch) {
const updateHighlightAll = (!this._highlightMatches && // Immediately trigger searching for non-'find' operations, when the
this._state.highlightAll); // current state needs to be reset and matches re-calculated.
this._nextMatch();
} else if (cmd === 'findagain') {
this._nextMatch(); this._nextMatch();
// When the findbar was previously closed, and `highlightAll` is set, // When the findbar was previously closed, and `highlightAll` is set,
// ensure that the matches on all active pages are highlighted again. // ensure that the matches on all active pages are highlighted again.
if (updateHighlightAll) { if (findbarClosed && this._state.highlightAll) {
this._updateAllPages(); this._updateAllPages();
} }
} else { } else {