Skip to content

Commit 8a35cc3

Browse files
Move item kind before the item name
1 parent 7a09a68 commit 8a35cc3

File tree

6 files changed

+22
-35
lines changed

6 files changed

+22
-35
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ h1, h2, h3, h4, h5, h6,
190190
.mobile-topbar,
191191
.search-input,
192192
.search-results .result-name,
193+
.search-results .type-kind,
193194
.item-name > a,
194195
.out-of-band,
195196
span.since,
@@ -870,6 +871,10 @@ so that we can apply CSS-filters to change the arrow color in themes */
870871
}
871872

872873
.search-results > a > div {
874+
flex: 3;
875+
}
876+
877+
.search-results > a > div.type-kind {
873878
flex: 1;
874879
}
875880

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,7 @@ function initSearch(rawSearchIndex) {
18661866
const name = item.name;
18671867
const type = itemTypes[item.ty];
18681868
const longType = longItemTypes[item.ty];
1869-
let extra = longType.length !== 0 ? ` <i>(${longType})</i>` : "";
1869+
const typeName = longType.length !== 0 ? `${longType}` : "?";
18701870

18711871
length += 1;
18721872

@@ -1878,7 +1878,6 @@ function initSearch(rawSearchIndex) {
18781878
resultName.className = "result-name";
18791879

18801880
if (item.is_alias) {
1881-
extra = "";
18821881
const alias = document.createElement("span");
18831882
alias.className = "alias";
18841883

@@ -1892,9 +1891,15 @@ function initSearch(rawSearchIndex) {
18921891

18931892
resultName.appendChild(alias);
18941893
}
1894+
1895+
const typeDisplay = document.createElement("div");
1896+
typeDisplay.innerText = typeName;
1897+
typeDisplay.className = "type-kind";
1898+
link.appendChild(typeDisplay);
1899+
18951900
resultName.insertAdjacentHTML(
18961901
"beforeend",
1897-
item.displayPath + "<span class=\"" + type + "\">" + name + "</span>" + extra);
1902+
item.displayPath + "<span class=\"" + type + "\">" + name + "</span>");
18981903
link.appendChild(resultName);
18991904

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

tests/rustdoc-gui/search-reexport.goml

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ assert-attribute: (
1414
"//a[@class='result-import']",
1515
{"href": "../test_docs/index.html#reexport.TheStdReexport"},
1616
)
17-
assert-text: ("//a[@class='result-import']", "test_docs::TheStdReexport (re-export)")
17+
assert-text: ("a.result-import .result-name", "test_docs::TheStdReexport")
18+
assert-text: ("a.result-import .type-kind", "re-export")
1819
click: "//a[@class='result-import']"
1920
// We check that it has the background modified thanks to the focus.
2021
wait-for-css: ("//*[@id='reexport.TheStdReexport']", {"background-color": "rgb(73, 74, 61)"})
@@ -25,7 +26,7 @@ press-key: 'Enter'
2526
write: (".search-input", "AliasForTheStdReexport")
2627
wait-for: "//a[@class='result-import']"
2728
assert-text: (
28-
"//a[@class='result-import']",
29+
"a.result-import .result-name",
2930
"AliasForTheStdReexport - see test_docs::TheStdReexport",
3031
)
3132
// Same thing again, we click on it to ensure the background is once again set as expected.

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

+2-26
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ define-function: (
55
(result_kind, color, hover_color),
66
block {
77
assert-css: (".result-" + |result_kind| + " ." + |result_kind|, {"color": |color|}, ALL)
8-
assert-css: (".result-" + |result_kind| + " i", {"color": |default_color|})
8+
assert-css: (".result-" + |result_kind| + " .type-kind", {"color": |entry_color|})
99
assert-css: (
1010
".result-" + |result_kind|,
1111
{"color": |entry_color|, "background-color": |background_color|},
@@ -19,7 +19,7 @@ define-function: (
1919
".result-" + |result_kind| + ":hover ." + |result_kind|,
2020
{"color": |hover_color|},
2121
)
22-
assert-css: (".result-" + |result_kind| + ":hover i", {"color": |default_color|})
22+
assert-css: (".result-" + |result_kind| + ":hover .type-kind", {"color": |hover_entry_color|})
2323
move-cursor-to: ".search-input"
2424
focus: ".result-" + |result_kind|
2525
assert-css: (
@@ -67,14 +67,6 @@ assert-css: (
6767
{"border-bottom-color": "#aaa3"}
6868
)
6969

70-
store-value: (default_color, "rgb(197, 197, 197)")
71-
72-
// Checking the color of "keyword" text.
73-
assert-css: (
74-
"//*[@class='result-name']//*[text()='(keyword)']",
75-
{"color": |default_color|},
76-
)
77-
7870
store-value: (entry_color, "#0096cf") // color of the search entry
7971
store-value: (hover_entry_color, "#fff") // color of the hovered/focused search entry
8072
store-value: (background_color, "transparent") // background color
@@ -186,14 +178,6 @@ assert-css: (
186178
{"border-bottom-color": "#aaa3"}
187179
)
188180

189-
store-value: (default_color, "rgb(221, 221, 221)")
190-
191-
// Checking the color for "keyword" text.
192-
assert-css: (
193-
"//*[@class='result-name']//*[text()='(keyword)']",
194-
{"color": |default_color|},
195-
)
196-
197181
store-value: (entry_color, "#ddd") // color of the search entry
198182
store-value: (hover_entry_color, "#ddd") // color of the hovered/focused search entry
199183
store-value: (background_color, "transparent") // background color
@@ -290,14 +274,6 @@ assert-css: (
290274
{"border-bottom-color": "#aaa3"}
291275
)
292276

293-
store-value: (default_color, "rgb(0, 0, 0)")
294-
295-
// Checking the color for "keyword" text.
296-
assert-css: (
297-
"//*[@class='result-name']//*[text()='(keyword)']",
298-
{"color": |default_color|},
299-
)
300-
301277
store-value: (entry_color, "#000") // color of the search entry
302278
store-value: (hover_entry_color, "#000") // color of the hovered/focused search entry
303279
store-value: (background_color, "transparent") // background color

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ 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": "310px"})
10+
assert-size: (".search-results div.desc", {"width": 259})
1111
set-window-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.
14-
assert-css: (".search-results div.desc", {"width": "566px"})
14+
assert-size: (".search-results div.desc", {"width": 566})
1515

1616
// The result set is all on one line.
1717
assert-css: (".search-results .result-name > span", {"display": "inline"})

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ wait-for: "#search-tabs"
99
// less good.
1010
//
1111
// Checking that the CSS is displaying " (keyword)" in italic.
12-
assert-text: (".result-keyword span.keyword + i", "(keyword)")
13-
assert-text: (".result-keyword .result-name", "CookieMonster (keyword)")
12+
assert-text: (".result-keyword .type-kind", "keyword")
13+
assert-text: (".result-keyword .result-name", "CookieMonster")

0 commit comments

Comments
 (0)