From 43c9a5eb6a19d4056749718e11f16296be2d52c2 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 25 Jan 2021 22:19:44 -0500 Subject: [PATCH] Fix search box resizing (#1316) * Don't resize the search box unless it's necessary * Allow search box to shrink under certain circumstances --- ext/bg/js/search.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index 3b7e8299..b445c161 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -149,13 +149,15 @@ class DisplaySearch extends Display { if (typeof source !== 'string') { source = ''; } - this._queryInput.value = source; - this._updateSearchHeight(); + if (this._queryInput.value !== source) { + this._queryInput.value = source; + this._updateSearchHeight(true); + } this._setIntroVisible(!valid, animate); } _onSearchInput() { - this._updateSearchHeight(); + this._updateSearchHeight(false); } _onSearchKeydown(e) { @@ -185,6 +187,7 @@ class DisplaySearch extends Display { text = text.substring(0, maximumClipboardSearchLength); } this._queryInput.value = text; + this._updateSearchHeight(true); this._search(animate, false, autoSearchClipboardContent); } @@ -357,11 +360,14 @@ class DisplaySearch extends Display { this.setContent(details); } - _updateSearchHeight() { + _updateSearchHeight(shrink) { const node = this._queryInput; + if (shrink) { + node.style.height = '0'; + } const {scrollHeight} = node; const currentHeight = node.getBoundingClientRect().height; - if (scrollHeight >= currentHeight - 1) { + if (shrink || scrollHeight >= currentHeight - 1) { node.style.height = `${scrollHeight}px`; } }