about summary refs log tree commit diff stats
path: root/frontend/static/search.js
diff options
context:
space:
mode:
authorAlan Pearce2024-05-12 13:19:48 +0200
committerAlan Pearce2024-05-12 13:19:48 +0200
commitb517b1e0e1933b310bcbbd718fc664f87226d3b6 (patch)
tree6e64708b46ba28d5a487241b45e56c20f25db869 /frontend/static/search.js
parent84acac6ddf46351d4c049c7bb25d72584b2c0fb7 (diff)
downloadsearchix-b517b1e0e1933b310bcbbd718fc664f87226d3b6.tar.lz
searchix-b517b1e0e1933b310bcbbd718fc664f87226d3b6.tar.zst
searchix-b517b1e0e1933b310bcbbd718fc664f87226d3b6.zip
feat(js): save and restore input state with history
Diffstat (limited to 'frontend/static/search.js')
-rw-r--r--frontend/static/search.js5
1 files changed, 4 insertions, 1 deletions
diff --git a/frontend/static/search.js b/frontend/static/search.js
index 0ca6d45..cadae32 100644
--- a/frontend/static/search.js
+++ b/frontend/static/search.js
@@ -6,8 +6,10 @@ const range = new Range();
 range.setStartAfter(search);
 range.setEndAfter(search.parentNode.lastChild);
 
+let urlLocation = new URL(location);
 let state = history.state || {
-  url: new URL(location).toString(),
+  url: urlLocation.toString(),
+  input: urlLocation.searchParams.get("query"),
   fragment: range.cloneContents().innerHTML || "",
   opened: [],
 };
@@ -117,6 +119,7 @@ addEventListener("popstate", function (ev) {
   if (ev.state != null) {
     url = new URL(ev.state.url);
     if (!url.pathname.endsWith("/search") && ev.state.fragment !== null) {
+      document.getElementById("query").value = ev.state.input;
       renderFragmentHTML(ev.state.fragment);
       return;
     }