diff --git a/web/pdf_find_bar.js b/web/pdf_find_bar.js index c1d7132c5..cefd50017 100644 --- a/web/pdf_find_bar.js +++ b/web/pdf_find_bar.js @@ -140,10 +140,10 @@ class PDFFindBar { this.findField.setAttribute('data-status', status); Promise.resolve(findMsg).then((msg) => { this.findMsg.textContent = msg; + this._adjustWidth(); }); this.updateResultsCount(matchCount); - this._adjustWidth(); } updateResultsCount(matchCount) { @@ -151,15 +151,18 @@ class PDFFindBar { return; // No UI control is provided. } - // If there are no matches, hide the counter. if (!matchCount) { + // If there are no matches, hide and reset the counter. this.findResultsCount.classList.add('hidden'); - return; + this.findResultsCount.textContent = ''; + } else { + // Update and show the match counter. + this.findResultsCount.textContent = matchCount.toLocaleString(); + this.findResultsCount.classList.remove('hidden'); } - - // Create and show the match counter. - this.findResultsCount.textContent = matchCount.toLocaleString(); - this.findResultsCount.classList.remove('hidden'); + // Since `updateResultsCount` may be called from `PDFFindController`, + // ensure that the width of the findbar is always updated correctly. + this._adjustWidth(); } open() {