From 2040b82aae6e6bd0eff6c843270d26b31e6213b6 Mon Sep 17 00:00:00 2001 From: massi Date: Tue, 15 Jul 2025 15:27:53 -0700 Subject: [PATCH] Update naming for clarity. Use search input on load if populated. After the wasm loads, check the search input for a value. If present, this means the user typed something into it during load - we should use that value for the initial search state instead of always respecting what the hash's search value is. Updates for clarity: - history.state: {} => "keepScrollPosition" We're using state as a flag, but as it was an empty object, wasn't clear to me what it was being used for. Hopefully this state's value will be self-documenting and provide more clarity for future contributors. - onHashChange => handleNavigation onHashChange implies there's a onhashchange event that's being handled, which isn't the case. --- lib/docs/main.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/docs/main.js b/lib/docs/main.js index 330b51ba49d1..a1a90f77fd49 100644 --- a/lib/docs/main.js +++ b/lib/docs/main.js @@ -128,7 +128,7 @@ domSearch.addEventListener('keydown', onSearchKeyDown, false); domSearch.addEventListener('input', onSearchChange, false); window.addEventListener('keydown', onWindowKeyDown, false); - onHashChange(null); + handleNavigation(null, domSearch.value ? computeSearchHash() : location.hash); }); }); @@ -642,14 +642,14 @@ } } - function onHashChange(state) { - history.replaceState({}, ""); - navigate(location.hash); + function handleNavigation(state, location_hash) { + history.replaceState("keepScrollPosition", ""); + navigate(location_hash); if (state == null) window.scrollTo({top: 0}); } function onPopState(ev) { - onHashChange(ev.state); + handleNavigation(ev.state, location.hash); } function navigate(location_hash) {