From bebd70b4e2d8da54b556b488d68a5111f3ff20c1 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sat, 26 Oct 2019 16:39:43 +0300 Subject: [PATCH] remember search history --- ext/bg/js/search.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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);