From bc04d1c44a58ee5de972328f7a62d11c9251c210 Mon Sep 17 00:00:00 2001 From: Accusys Date: Fri, 22 May 2026 10:56:29 +0800 Subject: [PATCH] fix: persist search query across refresh via sessionStorage --- docs_v1.0/doc_wasm/index.html | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/docs_v1.0/doc_wasm/index.html b/docs_v1.0/doc_wasm/index.html index 7893514..2799cfa 100644 --- a/docs_v1.0/doc_wasm/index.html +++ b/docs_v1.0/doc_wasm/index.html @@ -228,6 +228,7 @@ function showSearchResult(module, q) { } function clearSearch() { + sessionStorage.removeItem('doc_search_q'); var el = document.getElementById('search'); el.value = ''; el.focus(); @@ -290,6 +291,8 @@ async function initApp() { var clearEl = document.getElementById('search-clear'); searchEl.oninput = function() { var q = this.value.toLowerCase().trim(); + if (q) { sessionStorage.setItem('doc_search_q', q); } + else { sessionStorage.removeItem('doc_search_q'); } clearEl.style.display = q ? 'block' : 'none'; if (q.length < 2) { moduleListEl.style.display = ''; @@ -327,6 +330,7 @@ async function initApp() { try { await fetch('/api/v1/auth/logout', {method:'POST', credentials:'include'}); } catch(_) {} + sessionStorage.removeItem('doc_search_q'); // Clear client-side cookies document.cookie.split(';').forEach(function(c) { document.cookie = c.trim().split('=')[0] + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'; @@ -335,9 +339,20 @@ async function initApp() { showLoginForm(); }; - // Load initial module from hash or default - var hash = location.hash.slice(1); - await loadDoc(hash || '01_auth'); + // Restore search query across page refresh + var savedQ = sessionStorage.getItem('doc_search_q'); + if (savedQ) { + searchEl.value = savedQ; + clearEl.style.display = 'block'; + moduleListEl.style.display = 'none'; + searchResultsEl.style.display = 'block'; + searchResultsEl.innerHTML = '

Restoring search...

'; + fulltextSearch(savedQ); + } else { + // Load initial module from hash or default + var hash = location.hash.slice(1); + await loadDoc(hash || '01_auth'); + } } catch(e) { el.innerHTML = '

Init error: ' + e.message + '

'+e.stack+'
'; }