Skip to content

Commit d28f27e

Browse files
authored
Unrolled build for #146385
Rollup merge of #146385 - notriddle:no-anim, r=GuillaumeGomez rustdoc-search: redesign throbber to be less distracting Preview: https://notriddle.com/rustdoc-html-demo-12/throbber/std/index.html <img width="1920" height="182" alt="image" src="https://github.com/user-attachments/assets/da838ee0-3f7a-4b10-ba92-f9ac52e9f723" /> <img width="1920" height="182" alt="image" src="https://github.com/user-attachments/assets/b5a59fc0-5d07-4981-b1dd-0b60556a0dd5" /> <img width="1920" height="182" alt="image" src="https://github.com/user-attachments/assets/bb587660-7b6c-40e1-a7ae-2270d530dcd4" /> Complaints about it being distracting, and causing people to wait until all of the results are loaded instead of using the incremental results as they come in, make me think it was a bad idea to put it in the tab. Part of #146048
2 parents 5767910 + c9293bf commit d28f27e

File tree

3 files changed

+54
-62
lines changed

3 files changed

+54
-62
lines changed

src/librustdoc/html/static/css/rustdoc.css

Lines changed: 13 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,12 +1987,10 @@ a.tooltip:hover::after {
19871987
color: inherit;
19881988
}
19891989
#search-tabs button:not(.selected) {
1990-
--search-tab-button-background: var(--search-tab-button-not-selected-background);
19911990
background-color: var(--search-tab-button-not-selected-background);
19921991
border-top-color: var(--search-tab-button-not-selected-border-top-color);
19931992
}
19941993
#search-tabs button:hover, #search-tabs button.selected {
1995-
--search-tab-button-background: var(--search-tab-button-selected-background);
19961994
background-color: var(--search-tab-button-selected-background);
19971995
border-top-color: var(--search-tab-button-selected-border-top-color);
19981996
}
@@ -2008,66 +2006,27 @@ a.tooltip:hover::after {
20082006
color: transparent;
20092007
}
20102008

2011-
.search-form.loading {
2012-
--search-tab-button-background: var(--button-background-color);
2013-
}
2014-
2015-
#search-tabs .count.loading::before,
2016-
.search-form.loading::before
2017-
{
2018-
width: 16px;
2019-
height: 16px;
2020-
border-radius: 16px;
2021-
background: radial-gradient(
2022-
var(--search-tab-button-background) 0 50%,
2023-
transparent 50% 100%
2024-
), conic-gradient(
2025-
var(--code-highlight-kw-color) 0deg 30deg,
2026-
var(--code-highlight-prelude-color) 30deg 60deg,
2027-
var(--code-highlight-number-color) 90deg 120deg,
2028-
var(--code-highlight-lifetime-color ) 120deg 150deg,
2029-
var(--code-highlight-comment-color) 150deg 180deg,
2030-
var(--code-highlight-self-color) 180deg 210deg,
2031-
var(--code-highlight-attribute-color) 210deg 240deg,
2032-
var(--code-highlight-literal-color) 210deg 240deg,
2033-
var(--code-highlight-macro-color) 240deg 270deg,
2034-
var(--code-highlight-question-mark-color) 270deg 300deg,
2035-
var(--code-highlight-prelude-val-color) 300deg 330deg,
2036-
var(--code-highlight-doc-comment-color) 330deg 360deg
2037-
);
2038-
content: "";
2039-
position: absolute;
2040-
left: 2px;
2041-
top: 2px;
2042-
animation: rotating 1.25s linear infinite;
2043-
}
2044-
#search-tabs .count.loading::after,
20452009
.search-form.loading::after
20462010
{
20472011
width: 18px;
20482012
height: 18px;
20492013
border-radius: 18px;
2050-
background: conic-gradient(
2051-
var(--search-tab-button-background) 0deg 180deg,
2052-
transparent 270deg 360deg
2053-
);
2054-
content: "";
2014+
/* hourglass */
2015+
content: url('data:image/svg+xml,\
2016+
<svg width="16" height="16" viewBox="0 0 8 8" xmlns="http://www.w3.org/2000/svg">\
2017+
<g fill="none">\
2018+
<path d="m3.019 1.496v1.496l0.5878 1.018-0.5751 0.996v1.494" stroke="%233f3f3f"/>\
2019+
<path d="m5.003 1.496v1.496l-0.5878 1.018 0.5751 0.996v1.494" stroke="%233f3f3f"/>\
2020+
<path d="m2.006 1.5h3.978" stroke="%23000"/>\
2021+
<path d="m2.006 6.49h3.993" stroke="%23000"/>\
2022+
</g>\
2023+
<path d="m4.005 5.301-0.3987 0.6905h0.7977z" fill="%237f7f7f"/>\
2024+
<path d="m4.011 3.712-0.3987-0.6905h0.7977z" fill="%237f7f7f"/>\
2025+
</svg>');
20552026
position: absolute;
2056-
left: 1px;
2057-
top: 1px;
2058-
animation: rotating 0.66s linear infinite;
2059-
}
2060-
2061-
.search-form.loading::before {
2062-
left: auto;
2063-
right: 9px;
2064-
top: 8px;
2065-
}
2066-
2067-
.search-form.loading::after {
2068-
left: auto;
20692027
right: 8px;
20702028
top: 8px;
2029+
filter: var(--settings-menu-filter);
20712030
}
20722031

20732032
#search .error code {

src/librustdoc/html/static/js/search.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ignore-tidy-filelength
2-
/* global addClass, getNakedUrl, getVar, nonnull, getSettingValue */
2+
/* global addClass, getNakedUrl, getVar, getSettingValue, hasClass, nonnull */
33
/* global onEachLazy, removeClass, searchState, browserSupportsHistoryApi */
44

55
"use strict";
@@ -4804,6 +4804,15 @@ function printTab(nb) {
48044804
if (nb === iter) {
48054805
addClass(elem, "selected");
48064806
foundCurrentTab = true;
4807+
onEachLazy(document.querySelectorAll(
4808+
".search-form",
4809+
), form => {
4810+
if (hasClass(elem.firstElementChild, "loading")) {
4811+
addClass(form, "loading");
4812+
} else {
4813+
removeClass(form, "loading");
4814+
}
4815+
});
48074816
} else {
48084817
removeClass(elem, "selected");
48094818
}
@@ -5019,7 +5028,9 @@ ${obj.displayPath}<span class="${type}">${name}</span>\
50195028
await Promise.all(descList);
50205029
// need to make sure the element is shown before
50215030
// running this callback
5022-
yieldToBrowser().then(() => finishedCallback(count, output));
5031+
yieldToBrowser().then(() => {
5032+
finishedCallback(count, output);
5033+
});
50235034
}
50245035
});
50255036
};
@@ -5156,6 +5167,7 @@ function makeTab(tabNb, text, results, query, isTypeSearch, goToFirst) {
51565167
count < 100 ? `\u{2007}(${count})\u{2007}` : `\u{2007}(${count})`;
51575168
tabCount.innerHTML = fmtNbElems;
51585169
tabCount.className = "count";
5170+
printTab(window.searchState.currentTab);
51595171
}, isTypeSearch),
51605172
];
51615173
}
@@ -5215,9 +5227,12 @@ async function showResults(docSearch, results, goToFirst, filterCrates) {
52155227
resultsElem.id = "results";
52165228

52175229
search.innerHTML = "";
5218-
for (const [tab, output] of tabs) {
5230+
for (const [tabNb, [tab, output]] of tabs.entries()) {
52195231
tabsElem.appendChild(tab);
5232+
const isCurrentTab = window.searchState.currentTab === tabNb;
52205233
const placeholder = document.createElement("div");
5234+
placeholder.className = isCurrentTab ? "search-results active" : "search-results";
5235+
placeholder.innerHTML = "Loading...";
52215236
output.then(output => {
52225237
if (placeholder.parentElement) {
52235238
placeholder.parentElement.replaceChild(output, placeholder);
@@ -5474,11 +5489,6 @@ if (ROOT_PATH === null) {
54745489
const database = await Stringdex.loadDatabase(hooks);
54755490
if (typeof window !== "undefined") {
54765491
docSearch = new DocSearch(ROOT_PATH, database);
5477-
onEachLazy(document.querySelectorAll(
5478-
".search-form.loading",
5479-
), form => {
5480-
removeClass(form, "loading");
5481-
});
54825492
registerSearchEvents();
54835493
// If there's a search term in the URL, execute the search now.
54845494
if (window.searchState.getQueryStringParams().search !== undefined) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// We are intentionally triggering errors for race-free throbber test
2+
fail-on-request-error: false
3+
fail-on-js-error: false
4+
5+
// First, make sure the throbber goes away when done
6+
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html?search="
7+
wait-for: ".search-input"
8+
wait-for-false: ".search-form.loading"
9+
write-into: (".search-input", "test")
10+
press-key: 'Enter'
11+
wait-for-false: ".search-form.loading"
12+
13+
// Make sure the throbber shows up if we prevent the search from
14+
// ever finishing (this tactic is needed to make sure we don't get stuck
15+
// with any race conditions).
16+
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html?search="
17+
block-network-request: "*/desc/*.js"
18+
reload:
19+
wait-for: ".search-input"
20+
wait-for-false: ".search-form.loading"
21+
write-into: (".search-input", "test")
22+
press-key: 'Enter'
23+
wait-for: ".search-form.loading"

0 commit comments

Comments
 (0)