diff options
Diffstat (limited to 'ext/bg/js/search.js')
-rw-r--r-- | ext/bg/js/search.js | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index 6481e16a..d66e68b8 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -58,6 +58,8 @@ class DisplaySearch extends Display { window.wanakana.bind(this.query); } + window.addEventListener('popstate', (e) => this.onPopState(e)); + this.updateSearchButton(); } catch (e) { this.onError(e); @@ -95,10 +97,23 @@ class DisplaySearch extends Display { const query = this.query.value; const queryString = query.length > 0 ? `?query=${encodeURIComponent(query)}` : ''; - window.history.replaceState(null, '', `${window.location.pathname}${queryString}`); + window.history.pushState({query}, '', `${window.location.pathname}${queryString}`); this.onSearchQueryUpdated(query, true); } + onPopState(e) { + let query = ''; + if (e.state && e.state.query) { + query = e.state.query + } + + if (this.query !== null) { + this.query.value = query; + } + + this.onSearchQueryUpdated(query, false); + } + onKeyDown(e) { const key = Display.getKeyFromEvent(e); |