rustdoc-search: keep hourglass in searchbar

This commit is contained in:
Michael Howell 2025-10-07 11:17:44 -07:00
parent 5c31880034
commit 6d4b4d9ef0
2 changed files with 13 additions and 23 deletions

View file

@ -339,7 +339,6 @@ summary.hideme,
.scraped-example-list,
.rustdoc-breadcrumbs,
.search-switcher,
.search-throbber,
/* This selector is for the items listed in the "all items" page. */
ul.all-items {
font-family: "Fira Sans", Arial, NanumBarunGothic, sans-serif;
@ -2007,12 +2006,6 @@ a.tooltip:hover::after {
color: transparent;
}
.search-throbber {
position: relative;
height: 34px;
}
.search-throbber::after,
.search-form.loading::after
{
width: 18px;

View file

@ -1,5 +1,5 @@
// ignore-tidy-filelength
/* global addClass, getNakedUrl, getVar, nonnull, getSettingValue */
/* global addClass, getNakedUrl, getVar, getSettingValue, hasClass, nonnull */
/* global onEachLazy, removeClass, searchState, browserSupportsHistoryApi */
"use strict";
@ -4804,6 +4804,15 @@ function printTab(nb) {
if (nb === iter) {
addClass(elem, "selected");
foundCurrentTab = true;
onEachLazy(document.querySelectorAll(
".search-form",
), form => {
if (hasClass(elem.firstElementChild, "loading")) {
addClass(form, "loading");
} else {
removeClass(form, "loading");
}
});
} else {
removeClass(elem, "selected");
}
@ -4904,11 +4913,6 @@ async function addTab(results, query, display, finishedCallback, isTypeSearch) {
let output = document.createElement("ul");
output.className = "search-results " + extraClass;
const throbber = document.createElement("div");
throbber.className = "search-throbber";
throbber.innerHTML = "Loading...";
output.appendChild(throbber);
let count = 0;
/** @type {Promise<string|null>[]} */
@ -5015,7 +5019,7 @@ ${obj.displayPath}<span class="${type}">${name}</span>\
}
link.appendChild(description);
output.insertBefore(link, throbber);
output.appendChild(link);
results.next().then(async nextResult => {
if (nextResult.value) {
@ -5026,7 +5030,6 @@ ${obj.displayPath}<span class="${type}">${name}</span>\
// running this callback
yieldToBrowser().then(() => {
finishedCallback(count, output);
throbber.remove();
});
}
});
@ -5164,6 +5167,7 @@ function makeTab(tabNb, text, results, query, isTypeSearch, goToFirst) {
count < 100 ? `\u{2007}(${count})\u{2007}` : `\u{2007}(${count})`;
tabCount.innerHTML = fmtNbElems;
tabCount.className = "count";
printTab(window.searchState.currentTab);
}, isTypeSearch),
];
}
@ -5227,9 +5231,7 @@ async function showResults(docSearch, results, goToFirst, filterCrates) {
tabsElem.appendChild(tab);
const isCurrentTab = window.searchState.currentTab === tabNb;
const placeholder = document.createElement("div");
placeholder.className = isCurrentTab ?
"search-throbber search-results active" :
"search-throbber search-results";
placeholder.className = isCurrentTab ? "search-results active" : "search-results";
placeholder.innerHTML = "Loading...";
output.then(output => {
if (placeholder.parentElement) {
@ -5487,11 +5489,6 @@ if (ROOT_PATH === null) {
const database = await Stringdex.loadDatabase(hooks);
if (typeof window !== "undefined") {
docSearch = new DocSearch(ROOT_PATH, database);
onEachLazy(document.querySelectorAll(
".search-form.loading",
), form => {
removeClass(form, "loading");
});
registerSearchEvents();
// If there's a search term in the URL, execute the search now.
if (window.searchState.getQueryStringParams().search !== undefined) {