Skip to content

Commit 5871bc8

Browse files
authored
Rollup merge of #113100 - GuillaumeGomez:search-result-long-name, r=notriddle
Fix display of long items in search results Fixes #113060. You can test the result [here](https://rustdoc.crud.net/imperio/search-result-long-name/lib2/index.html). To make it a bit better, I also reduced a bit the size of the short documentation from half to 2 fifth of the width. r? `@notriddle`
2 parents 376c944 + a716c79 commit 5871bc8

File tree

4 files changed

+66
-20
lines changed

4 files changed

+66
-20
lines changed

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

+24-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
:root {
1010
--nav-sub-mobile-padding: 8px;
11+
--search-typename-width: 6.75rem;
1112
}
1213

1314
/* See FiraSans-LICENSE.txt for the Fira Sans license. */
@@ -869,32 +870,39 @@ so that we can apply CSS-filters to change the arrow color in themes */
869870
gap: 1em;
870871
}
871872

872-
.search-results > a > div {
873-
flex: 1;
874-
}
875-
876873
.search-results > a > div.desc {
877874
white-space: nowrap;
878875
text-overflow: ellipsis;
879876
overflow: hidden;
877+
flex: 2;
880878
}
881879

882880
.search-results a:hover,
883881
.search-results a:focus {
884882
background-color: var(--search-result-link-focus-background-color);
885883
}
886884

885+
.search-results .result-name {
886+
display: flex;
887+
align-items: center;
888+
justify-content: start;
889+
flex: 3;
890+
}
887891
.search-results .result-name span.alias {
888892
color: var(--search-results-alias-color);
889893
}
890894
.search-results .result-name .grey {
891895
color: var(--search-results-grey-color);
892896
}
893897
.search-results .result-name .typename {
894-
display: inline-block;
895898
color: var(--search-results-grey-color);
896899
font-size: 0.875rem;
897-
width: 6.25rem;
900+
width: var(--search-typename-width);
901+
}
902+
.search-results .result-name .path {
903+
word-break: break-all;
904+
max-width: calc(100% - var(--search-typename-width));
905+
display: inline-block;
898906
}
899907

900908
.popover {
@@ -1730,6 +1738,16 @@ in source-script.js
17301738
.search-results > a > div.desc, .item-table > li > div.desc {
17311739
padding-left: 2em;
17321740
}
1741+
.search-results .result-name {
1742+
display: block;
1743+
}
1744+
.search-results .result-name .typename {
1745+
width: initial;
1746+
margin-right: 0;
1747+
}
1748+
.search-results .result-name .typename, .search-results .result-name .path {
1749+
display: inline;
1750+
}
17331751

17341752
.source-sidebar-expanded .source .sidebar {
17351753
max-width: 100vw;

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -2024,9 +2024,11 @@ function initSearch(rawSearchIndex) {
20242024

20252025
resultName.insertAdjacentHTML(
20262026
"beforeend",
2027-
`<span class="typename">${typeName}</span>`
2028-
+ ` ${item.displayPath}<span class="${type}">${name}</span>`
2029-
);
2027+
`\
2028+
<span class="typename">${typeName}</span>\
2029+
<div class="path">\
2030+
${item.displayPath}<span class="${type}">${name}</span>\
2031+
</div>`);
20302032
link.appendChild(resultName);
20312033

20322034
const description = document.createElement("div");

tests/rustdoc-gui/search-result-color.goml

+8-8
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ assert-css: (
6161
{"color": "#c5c5c5"},
6262
)
6363
assert-css: (
64-
"//*[@class='result-name']/*[text()='test_docs::']",
64+
"//*[@class='result-name']//*[text()='test_docs::']",
6565
{"color": "#0096cf"},
6666
)
6767

@@ -138,19 +138,19 @@ call-function: (
138138
move-cursor-to: ".search-input"
139139
focus: ".search-input" // To ensure the `<a>` container isnt focus or hover.
140140
assert-css: (
141-
"//*[@class='result-name']/*[text()='test_docs::']/ancestor::a",
141+
"//*[@class='result-name']//*[text()='test_docs::']/ancestor::a",
142142
{"color": "#0096cf", "background-color": "transparent"},
143143
ALL,
144144
)
145145

146146
// Checking color and background on hover.
147147
move-cursor-to: "//*[@class='desc'][text()='Just a normal struct.']"
148148
assert-css: (
149-
"//*[@class='result-name']/*[text()='test_docs::']",
149+
"//*[@class='result-name']//*[text()='test_docs::']",
150150
{"color": "#fff"},
151151
)
152152
assert-css: (
153-
"//*[@class='result-name']/*[text()='test_docs::']/ancestor::a",
153+
"//*[@class='result-name']//*[text()='test_docs::']/ancestor::a",
154154
{"color": "#fff", "background-color": "rgb(60, 60, 60)"},
155155
)
156156

@@ -173,7 +173,7 @@ assert-css: (
173173
{"color": "#ddd"},
174174
)
175175
assert-css: (
176-
"//*[@class='result-name']/*[text()='test_docs::']",
176+
"//*[@class='result-name']//*[text()='test_docs::']",
177177
{"color": "#ddd"},
178178
)
179179

@@ -250,7 +250,7 @@ call-function: (
250250
move-cursor-to: ".search-input"
251251
focus: ".search-input" // To ensure the `<a>` container isnt focus or hover.
252252
assert-css: (
253-
"//*[@class='result-name']/*[text()='test_docs::']/ancestor::a",
253+
"//*[@class='result-name']//*[text()='test_docs::']/ancestor::a",
254254
{"color": "#ddd", "background-color": "transparent"},
255255
)
256256

@@ -270,7 +270,7 @@ assert-css: (
270270
{"color": "#000"},
271271
)
272272
assert-css: (
273-
"//*[@class='result-name']/*[text()='test_docs::']",
273+
"//*[@class='result-name']//*[text()='test_docs::']",
274274
{"color": "#000"},
275275
)
276276

@@ -347,7 +347,7 @@ call-function: (
347347
move-cursor-to: ".search-input"
348348
focus: ".search-input" // To ensure the `<a>` container isnt focus or hover.
349349
assert-css: (
350-
"//*[@class='result-name']/*[text()='test_docs::']/ancestor::a",
350+
"//*[@class='result-name']//*[text()='test_docs::']/ancestor::a",
351351
{"color": "#000", "background-color": "transparent"},
352352
)
353353

tests/rustdoc-gui/search-result-display.goml

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore-tidy-linelength
12
// Checks that the search results have the expected width.
23
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
34
set-window-size: (900, 1000)
@@ -7,15 +8,40 @@ press-key: 'Enter'
78
wait-for: "#crate-search"
89
// The width is returned by "getComputedStyle" which returns the exact number instead of the
910
// CSS rule which is "50%"...
10-
assert-size: (".search-results div.desc", {"width": 310})
11+
assert-size: (".search-results div.desc", {"width": 248})
12+
store-size: (".search-results .result-name .typename", {"width": width})
1113
set-window-size: (600, 100)
1214
// As counter-intuitive as it may seem, in this width, the width is "100%", which is why
1315
// when computed it's larger.
1416
assert-size: (".search-results div.desc", {"width": 566})
1517

1618
// The result set is all on one line.
17-
assert-css: (".search-results .result-name > span:not(.typename)", {"display": "inline"})
18-
assert-css: (".search-results .result-name > span.typename", {"display": "inline-block"})
19+
compare-elements-position-near: (
20+
".search-results .result-name .typename",
21+
".search-results .result-name .path",
22+
{"y": 2},
23+
)
24+
compare-elements-position-near-false: (
25+
".search-results .result-name .typename",
26+
".search-results .result-name .path",
27+
{"x": 5},
28+
)
29+
// The width of the "typename" isn't fixed anymore in this display mode.
30+
store-size: (".search-results .result-name .typename", {"width": new_width})
31+
assert: |new_width| < |width| - 10
32+
33+
// Check that if the search is too long on mobile, it'll go under the "typename".
34+
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html?search=SuperIncrediblyLongLongLongLongLongLongLongGigaGigaGigaMegaLongLongLongStructName"
35+
wait-for: "#crate-search"
36+
compare-elements-position-near: (
37+
".search-results .result-name .typename",
38+
".search-results .result-name .path",
39+
{"y": 2, "x": 0},
40+
)
41+
store-size: (".search-results .result-name", {"width": width, "height": height})
42+
store-size: (".search-results .result-name .path", {"width": sub_width, "height": sub_height})
43+
assert: |width| < |sub_width| + 8 && |width| > |sub_width| - 8
44+
assert: |height| < |sub_height| + 8 && |height| > |sub_height| - 8
1945

2046
// Check that the crate filter `<select>` is correctly handled when it goes to next line.
2147
// To do so we need to update the length of one of its `<option>`.

0 commit comments

Comments
 (0)