Commit 9a158c1dae

massi <mdsiboldi@gmail.com>
2025-08-06 05:23:24
autodoc: Use the search input's value on load (#24467)
Co-authored-by: massi <git@massi.world>
1 parent d214910
Changed files (1)
lib
docs
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;