From 9132814ccf15ec2d1272c14e4840f4affad94706 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sat, 26 Oct 2019 14:30:36 +0300 Subject: focus and scroll to input only when it's needed --- ext/bg/js/search.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index d74998d6..1a6822f6 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -79,7 +79,11 @@ class DisplaySearch extends Display { onSearchInput() { this.updateSearchButton(); - this.query.scrollIntoView(); + + const queryElementRect = this.query.getBoundingClientRect(); + if (queryElementRect.top < 0 || queryElementRect.bottom > window.innerHeight) { + this.query.scrollIntoView(); + } } onSearch(e) { @@ -123,7 +127,7 @@ class DisplaySearch extends Display { } } - if (!super.onKeyDown(e) && !preventFocus) { + if (!super.onKeyDown(e) && !preventFocus && document.activeElement !== this.query) { this.query.focus({preventScroll: true}); } } -- cgit v1.2.3