remember search history
This commit is contained in:
parent
50769feea7
commit
bebd70b4e2
@ -58,6 +58,8 @@ class DisplaySearch extends Display {
|
|||||||
window.wanakana.bind(this.query);
|
window.wanakana.bind(this.query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.addEventListener('popstate', (e) => this.onPopState(e));
|
||||||
|
|
||||||
this.updateSearchButton();
|
this.updateSearchButton();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.onError(e);
|
this.onError(e);
|
||||||
@ -95,10 +97,23 @@ class DisplaySearch extends Display {
|
|||||||
|
|
||||||
const query = this.query.value;
|
const query = this.query.value;
|
||||||
const queryString = query.length > 0 ? `?query=${encodeURIComponent(query)}` : '';
|
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);
|
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) {
|
onKeyDown(e) {
|
||||||
const key = Display.getKeyFromEvent(e);
|
const key = Display.getKeyFromEvent(e);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user