Skip to content

Commit 9a158c1

Browse files
mdsibmassi
andauthored
autodoc: Use the search input's value on load (#24467)
Co-authored-by: massi <[email protected]>
1 parent d214910 commit 9a158c1

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/docs/main.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@
129129
domSearch.addEventListener('input', onSearchChange, false);
130130
window.addEventListener('keydown', onWindowKeyDown, false);
131131
onHashChange(null);
132+
if (domSearch.value) {
133+
// user started typing a search query while the page was loading
134+
curSearchIndex = -1;
135+
startAsyncSearch();
136+
}
132137
});
133138
});
134139

@@ -643,27 +648,32 @@
643648
}
644649

645650
function onHashChange(state) {
651+
// Use a non-null state value to prevent the window scrolling if the user goes back to this history entry.
646652
history.replaceState({}, "");
647653
navigate(location.hash);
648654
if (state == null) window.scrollTo({top: 0});
649655
}
650656

651657
function onPopState(ev) {
652658
onHashChange(ev.state);
659+
syncDomSearch();
653660
}
654661

655662
function navigate(location_hash) {
656663
updateCurNav(location_hash);
657-
if (domSearch.value !== curNavSearch) {
658-
domSearch.value = curNavSearch;
659-
}
660664
render();
661665
if (imFeelingLucky) {
662666
imFeelingLucky = false;
663667
activateSelectedResult();
664668
}
665669
}
666670

671+
function syncDomSearch() {
672+
if (domSearch.value !== curNavSearch) {
673+
domSearch.value = curNavSearch;
674+
}
675+
}
676+
667677
function activateSelectedResult() {
668678
if (domSectSearchResults.classList.contains("hidden")) {
669679
return;

0 commit comments

Comments
 (0)