motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit 9a158c1dae531f2a4e5667569bed38c27cbd4d57 (tree)
parent d2149106a6c03301d0467283814db86be030b335
Author: massi <mdsiboldi@gmail.com>
Date:   Tue,  5 Aug 2025 20:23:24 -0700

autodoc: Use the search input's value on load (#24467)

Co-authored-by: massi <git@massi.world>
Diffstat:
Mlib/docs/main.js | 16+++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/lib/docs/main.js b/lib/docs/main.js @@ -129,6 +129,11 @@ domSearch.addEventListener('input', onSearchChange, false); window.addEventListener('keydown', onWindowKeyDown, false); onHashChange(null); + if (domSearch.value) { + // user started typing a search query while the page was loading + curSearchIndex = -1; + startAsyncSearch(); + } }); }); @@ -643,6 +648,7 @@ } function onHashChange(state) { + // Use a non-null state value to prevent the window scrolling if the user goes back to this history entry. history.replaceState({}, ""); navigate(location.hash); if (state == null) window.scrollTo({top: 0}); @@ -650,13 +656,11 @@ function onPopState(ev) { onHashChange(ev.state); + syncDomSearch(); } function navigate(location_hash) { updateCurNav(location_hash); - if (domSearch.value !== curNavSearch) { - domSearch.value = curNavSearch; - } render(); if (imFeelingLucky) { imFeelingLucky = false; @@ -664,6 +668,12 @@ } } + function syncDomSearch() { + if (domSearch.value !== curNavSearch) { + domSearch.value = curNavSearch; + } + } + function activateSelectedResult() { if (domSectSearchResults.classList.contains("hidden")) { return;