remember search history

This commit is contained in:
siikamiika 2019-10-26 16:39:43 +03:00
parent 50769feea7
commit bebd70b4e2

View File

@ -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);