Skip to content

Commit 598364c

Browse files
authored
Rollup merge of rust-lang#92490 - jsha:crates-in-results, r=GuillaumeGomez
Move crate drop-down to search results page This reduces clutter on doc pages. Part of rust-lang#59840 r? ```@GuillaumeGomez``` Demo: https://rustdoc.crud.net/jsha/crates-in-results/std/index.html?search=str
2 parents 8dc3bf7 + 8abb4bb commit 598364c

File tree

7 files changed

+45
-40
lines changed

7 files changed

+45
-40
lines changed

src/ci/docker/host-x86_64/mingw-check/Dockerfile

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1717
pkg-config \
1818
mingw-w64
1919

20-
RUN curl -sL https://nodejs.org/dist/v14.4.0/node-v14.4.0-linux-x64.tar.xz | tar -xJ
21-
ENV PATH="/node-v14.4.0-linux-x64/bin:${PATH}"
20+
RUN curl -sL https://nodejs.org/dist/v16.9.0/node-v16.9.0-linux-x64.tar.xz | tar -xJ
21+
ENV PATH="/node-v16.9.0-linux-x64/bin:${PATH}"
2222
# Install es-check
2323
# Pin its version to prevent unrelated CI failures due to future es-check versions.
24-
RUN npm install es-check@5.2.3 -g
25-
RUN npm install eslint@7.20.0 -g
24+
RUN npm install es-check@6.1.1 -g
25+
RUN npm install eslint@8.6.0 -g
2626

2727
COPY scripts/sccache.sh /scripts/
2828
RUN sh /scripts/sccache.sh
@@ -40,5 +40,5 @@ ENV SCRIPT python3 ../x.py --stage 2 test src/tools/expand-yaml-anchors && \
4040
/scripts/validate-toolstate.sh && \
4141
/scripts/validate-error-codes.sh && \
4242
# Runs checks to ensure that there are no ES5 issues in our JS code.
43-
es-check es5 ../src/librustdoc/html/static/js/*.js && \
43+
es-check es6 ../src/librustdoc/html/static/js/*.js && \
4444
eslint ../src/librustdoc/html/static/js/*.js

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

+12-6
Original file line numberDiff line numberDiff line change
@@ -866,18 +866,24 @@ h2.small-section-header > .anchor {
866866
display: inline-flex;
867867
width: calc(100% - 63px);
868868
}
869+
.search-results-title {
870+
display: inline;
871+
}
872+
#search-settings {
873+
font-size: 1.5rem;
874+
font-weight: 500;
875+
margin-bottom: 20px;
876+
}
869877
#crate-search {
870878
min-width: 115px;
871879
margin-top: 5px;
872-
padding: 6px;
873-
padding-right: 19px;
874-
flex: none;
880+
margin-left: 0.2em;
881+
padding-left: 0.3em;
882+
padding-right: 23px;
875883
border: 0;
876-
border-right: 0;
877-
border-radius: 4px 0 0 4px;
884+
border-radius: 4px;
878885
outline: none;
879886
cursor: pointer;
880-
border-right: 1px solid;
881887
-moz-appearance: none;
882888
-webkit-appearance: none;
883889
/* Removes default arrow from firefox */

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

+22-17
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ window.initSearch = function(rawSearchIndex) {
10851085
return "<button>" + text + " <div class=\"count\">(" + nbElems + ")</div></button>";
10861086
}
10871087

1088-
function showResults(results, go_to_first) {
1088+
function showResults(results, go_to_first, filterCrates) {
10891089
var search = searchState.outputElement();
10901090
if (go_to_first || (results.others.length === 1
10911091
&& getSettingValue("go-to-only-result") === "true"
@@ -1126,9 +1126,16 @@ window.initSearch = function(rawSearchIndex) {
11261126
}
11271127
}
11281128

1129-
var output = "<h1>Results for " + escape(query.query) +
1129+
let crates = `<select id="crate-search"><option value="All crates">All crates</option>`;
1130+
for (let c of window.ALL_CRATES) {
1131+
crates += `<option value="${c}" ${c == filterCrates && "selected"}>${c}</option>`;
1132+
}
1133+
crates += `</select>`;
1134+
var output = `<div id="search-settings">
1135+
<h1 class="search-results-title">Results for ${escape(query.query)} ` +
11301136
(query.type ? " (type: " + escape(query.type) + ")" : "") + "</h1>" +
1131-
"<div id=\"titles\">" +
1137+
` in ${crates} ` +
1138+
`</div><div id="titles">` +
11321139
makeTabHeader(0, "In Names", ret_others[1]) +
11331140
makeTabHeader(1, "In Parameters", ret_in_args[1]) +
11341141
makeTabHeader(2, "In Return Types", ret_returned[1]) +
@@ -1141,6 +1148,7 @@ window.initSearch = function(rawSearchIndex) {
11411148
resultsElem.appendChild(ret_returned[0]);
11421149

11431150
search.innerHTML = output;
1151+
document.getElementById("crate-search").addEventListener("input", updateCrate);
11441152
search.appendChild(resultsElem);
11451153
// Reset focused elements.
11461154
searchState.focusedByTab = [null, null, null];
@@ -1316,7 +1324,8 @@ window.initSearch = function(rawSearchIndex) {
13161324
}
13171325

13181326
var filterCrates = getFilterCrates();
1319-
showResults(execSearch(query, searchWords, filterCrates), params["go_to_first"]);
1327+
showResults(execSearch(query, searchWords, filterCrates),
1328+
params["go_to_first"], filterCrates);
13201329
}
13211330

13221331
function buildIndex(rawSearchIndex) {
@@ -1552,19 +1561,6 @@ window.initSearch = function(rawSearchIndex) {
15521561
}
15531562
});
15541563

1555-
1556-
var selectCrate = document.getElementById("crate-search");
1557-
if (selectCrate) {
1558-
selectCrate.onchange = function() {
1559-
updateLocalStorage("rustdoc-saved-filter-crate", selectCrate.value);
1560-
// In case you "cut" the entry from the search input, then change the crate filter
1561-
// before paste back the previous search, you get the old search results without
1562-
// the filter. To prevent this, we need to remove the previous results.
1563-
currentResults = null;
1564-
search(undefined, true);
1565-
};
1566-
}
1567-
15681564
// Push and pop states are used to add search results to the browser
15691565
// history.
15701566
if (searchState.browserSupportsHistoryApi()) {
@@ -1616,6 +1612,15 @@ window.initSearch = function(rawSearchIndex) {
16161612
};
16171613
}
16181614

1615+
function updateCrate(ev) {
1616+
updateLocalStorage("rustdoc-saved-filter-crate", ev.target.value);
1617+
// In case you "cut" the entry from the search input, then change the crate filter
1618+
// before paste back the previous search, you get the old search results without
1619+
// the filter. To prevent this, we need to remove the previous results.
1620+
currentResults = null;
1621+
search(undefined, true);
1622+
}
1623+
16191624
searchWords = buildIndex(rawSearchIndex);
16201625
registerSearchEvents();
16211626
// If there's a search term in the URL, execute the search now.

src/librustdoc/html/templates/page.html

+1-5
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,7 @@
105105
</div> {#- -#}
106106
<form class="search-form"> {#- -#}
107107
<div class="search-container"> {#- -#}
108-
<div>{%- if layout.generate_search_filter -%}
109-
<select id="crate-search"> {#- -#}
110-
<option value="All crates">All crates</option> {#- -#}
111-
</select> {#- -#}
112-
{%- endif -%}
108+
<div>
113109
<input {# -#}
114110
class="search-input" {# -#}
115111
name="search" {# -#}

src/test/rustdoc-gui/escape-key.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
goto: file://|DOC_PATH|/test_docs/index.html
22
// First, we check that the search results are hidden when the Escape key is pressed.
33
write: (".search-input", "test")
4-
wait-for: "#search > h1" // The search element is empty before the first search
4+
wait-for: "#search h1" // The search element is empty before the first search
55
assert-attribute: ("#search", {"class": "content"})
66
assert-attribute: ("#main-content", {"class": "content hidden"})
77
press-key: "Escape"

src/test/rustdoc-gui/search-filter.goml

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ write: (".search-input", "test")
55
wait-for: "#titles"
66
assert-text: ("#results .externcrate", "test_docs")
77

8-
goto: file://|DOC_PATH|/test_docs/index.html
8+
wait-for: "#crate-search"
99
// We now want to change the crate filter.
1010
click: "#crate-search"
1111
// We select "lib2" option then press enter to change the filter.
1212
press-key: "ArrowDown"
1313
press-key: "Enter"
14-
// We now make the search again.
15-
write: (".search-input", "test")
1614
// Waiting for the search results to appear...
1715
wait-for: "#titles"
1816
// We check that there is no more "test_docs" appearing.

src/test/rustdoc-gui/toggle-docs-mobile.goml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
goto: file://|DOC_PATH|/test_docs/struct.Foo.html
22
size: (433, 600)
33
assert-attribute: (".top-doc", {"open": ""})
4-
click: (4, 280) // This is the position of the top doc comment toggle
4+
click: (4, 240) // This is the position of the top doc comment toggle
55
assert-attribute-false: (".top-doc", {"open": ""})
6-
click: (4, 280)
6+
click: (4, 240)
77
assert-attribute: (".top-doc", {"open": ""})
88
// To ensure that the toggle isn't over the text, we check that the toggle isn't clicked.
9-
click: (3, 280)
9+
click: (3, 240)
1010
assert-attribute: (".top-doc", {"open": ""})
1111

1212
// Assert the position of the toggle on the top doc block.

0 commit comments

Comments
 (0)