Skip to content

Commit ded8d03

Browse files
authored
Rollup merge of #103980 - notriddle:notriddle/search-results, r=GuillaumeGomez
rustdoc: simplify search results CSS and DOM Preview: http://notriddle.com/notriddle-rustdoc-demos/search-results/std/index.html?search=vec There is a layout change caused by this commit, but it's subtle. You won't notice it unless you're looking for it. ## Before ![image](https://user-images.githubusercontent.com/1593513/200060877-05ae4135-db8d-4d24-8dfa-4c06b8ef671c.png) ## After ![image](https://user-images.githubusercontent.com/1593513/200061474-b0ea9e8d-72c3-401f-9106-072307d9e2ff.png)
2 parents f6ca5aa + 4bd6748 commit ded8d03

File tree

4 files changed

+19
-32
lines changed

4 files changed

+19
-32
lines changed

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

+11-20
Original file line numberDiff line numberDiff line change
@@ -881,31 +881,24 @@ so that we can apply CSS-filters to change the arrow color in themes */
881881
display: block;
882882
}
883883

884-
.search-results .desc > span {
885-
white-space: nowrap;
886-
text-overflow: ellipsis;
887-
overflow: hidden;
888-
display: block;
889-
}
890-
891884
.search-results > a {
892-
display: block;
885+
display: flex;
893886
/* A little margin ensures the browser's outlining of focused links has room to display. */
894887
margin-left: 2px;
895888
margin-right: 2px;
896889
border-bottom: 1px solid var(--border-color);
890+
gap: 1em;
897891
}
898892

899893
.search-results > a > div {
900-
display: flex;
901-
flex-flow: row wrap;
894+
flex: 1;
902895
}
903896

904-
.search-results .result-name, .search-results div.desc {
905-
width: 50%;
906-
}
907-
.search-results .result-name {
908-
padding-right: 1em;
897+
.search-results > a > div.desc {
898+
white-space: nowrap;
899+
text-overflow: ellipsis;
900+
overflow: hidden;
901+
display: block;
909902
}
910903

911904
.search-results a:hover,
@@ -1867,18 +1860,16 @@ in storage.js
18671860
}
18681861

18691862
/* Display an alternating layout on tablets and phones */
1870-
.item-table, .item-row, .item-left, .item-right {
1863+
.item-table, .item-row, .item-left, .item-right,
1864+
.search-results > a, .search-results > a > div {
18711865
display: block;
18721866
}
18731867

18741868
/* Display an alternating layout on tablets and phones */
18751869
.search-results > a {
18761870
padding: 5px 0px;
18771871
}
1878-
.search-results .result-name, .search-results div.desc {
1879-
width: 100%;
1880-
}
1881-
.search-results div.desc, .item-right {
1872+
.search-results > a > div.desc, .item-right {
18821873
padding-left: 2em;
18831874
}
18841875

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

+3-7
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,6 @@ function initSearch(rawSearchIndex) {
15931593
link.className = "result-" + type;
15941594
link.href = item.href;
15951595

1596-
const wrapper = document.createElement("div");
15971596
const resultName = document.createElement("div");
15981597
resultName.className = "result-name";
15991598

@@ -1614,16 +1613,13 @@ function initSearch(rawSearchIndex) {
16141613
resultName.insertAdjacentHTML(
16151614
"beforeend",
16161615
item.displayPath + "<span class=\"" + type + "\">" + name + extra + "</span>");
1617-
wrapper.appendChild(resultName);
1616+
link.appendChild(resultName);
16181617

16191618
const description = document.createElement("div");
16201619
description.className = "desc";
1621-
const spanDesc = document.createElement("span");
1622-
spanDesc.insertAdjacentHTML("beforeend", item.desc);
1620+
description.insertAdjacentHTML("beforeend", item.desc);
16231621

1624-
description.appendChild(spanDesc);
1625-
wrapper.appendChild(description);
1626-
link.appendChild(wrapper);
1622+
link.appendChild(description);
16271623
output.appendChild(link);
16281624
});
16291625
} else if (query.error === null) {

src/test/rustdoc-gui/search-result-color.goml

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ reload:
6767
// Waiting for the search results to appear...
6868
wait-for: "#titles"
6969
assert-css: (
70-
"//*[@class='desc']//*[text()='Just a normal struct.']",
70+
"//*[@class='desc'][text()='Just a normal struct.']",
7171
{"color": "rgb(197, 197, 197)"},
7272
)
7373
assert-css: (
@@ -159,7 +159,7 @@ assert-css: (
159159
)
160160

161161
// Checking color and background on hover.
162-
move-cursor-to: "//*[@class='desc']//*[text()='Just a normal struct.']"
162+
move-cursor-to: "//*[@class='desc'][text()='Just a normal struct.']"
163163
assert-css: (
164164
"//*[@class='result-name']/*[text()='test_docs::']",
165165
{"color": "rgb(255, 255, 255)"},
@@ -179,7 +179,7 @@ reload:
179179
// Waiting for the search results to appear...
180180
wait-for: "#titles"
181181
assert-css: (
182-
"//*[@class='desc']//*[text()='Just a normal struct.']",
182+
"//*[@class='desc'][text()='Just a normal struct.']",
183183
{"color": "rgb(221, 221, 221)"},
184184
)
185185
assert-css: (
@@ -276,7 +276,7 @@ reload:
276276
// Waiting for the search results to appear...
277277
wait-for: "#titles"
278278
assert-css: (
279-
"//*[@class='desc']//*[text()='Just a normal struct.']",
279+
"//*[@class='desc'][text()='Just a normal struct.']",
280280
{"color": "rgb(0, 0, 0)"},
281281
)
282282
assert-css: (

src/test/rustdoc-gui/search-result-display.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ press-key: 'Enter'
77
wait-for: "#crate-search"
88
// The width is returned by "getComputedStyle" which returns the exact number instead of the
99
// CSS rule which is "50%"...
10-
assert-css: (".search-results div.desc", {"width": "318px"})
10+
assert-css: (".search-results div.desc", {"width": "310px"})
1111
size: (600, 100)
1212
// As counter-intuitive as it may seem, in this width, the width is "100%", which is why
1313
// when computed it's larger.

0 commit comments

Comments
 (0)