Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: simplify search results CSS and DOM #103980

Merged
merged 2 commits into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -881,31 +881,24 @@ so that we can apply CSS-filters to change the arrow color in themes */
display: block;
}

.search-results .desc > span {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
display: block;
}

.search-results > a {
display: block;
display: flex;
/* A little margin ensures the browser's outlining of focused links has room to display. */
margin-left: 2px;
margin-right: 2px;
border-bottom: 1px solid var(--border-color);
gap: 1em;
}

.search-results > a > div {
display: flex;
flex-flow: row wrap;
flex: 1;
}

.search-results .result-name, .search-results div.desc {
width: 50%;
}
.search-results .result-name {
padding-right: 1em;
.search-results > a > div.desc {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
display: block;
}

.search-results a:hover,
Expand Down Expand Up @@ -1867,18 +1860,16 @@ in storage.js
}

/* Display an alternating layout on tablets and phones */
.item-table, .item-row, .item-left, .item-right {
.item-table, .item-row, .item-left, .item-right,
.search-results > a, .search-results > a > div {
display: block;
}

/* Display an alternating layout on tablets and phones */
.search-results > a {
padding: 5px 0px;
}
.search-results .result-name, .search-results div.desc {
width: 100%;
}
.search-results div.desc, .item-right {
.search-results > a > div.desc, .item-right {
padding-left: 2em;
}

Expand Down
10 changes: 3 additions & 7 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,6 @@ function initSearch(rawSearchIndex) {
link.className = "result-" + type;
link.href = item.href;

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

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

const description = document.createElement("div");
description.className = "desc";
const spanDesc = document.createElement("span");
spanDesc.insertAdjacentHTML("beforeend", item.desc);
description.insertAdjacentHTML("beforeend", item.desc);

description.appendChild(spanDesc);
wrapper.appendChild(description);
link.appendChild(wrapper);
link.appendChild(description);
output.appendChild(link);
});
} else if (query.error === null) {
Expand Down
8 changes: 4 additions & 4 deletions src/test/rustdoc-gui/search-result-color.goml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ reload:
// Waiting for the search results to appear...
wait-for: "#titles"
assert-css: (
"//*[@class='desc']//*[text()='Just a normal struct.']",
"//*[@class='desc'][text()='Just a normal struct.']",
{"color": "rgb(197, 197, 197)"},
)
assert-css: (
Expand Down Expand Up @@ -159,7 +159,7 @@ assert-css: (
)

// Checking color and background on hover.
move-cursor-to: "//*[@class='desc']//*[text()='Just a normal struct.']"
move-cursor-to: "//*[@class='desc'][text()='Just a normal struct.']"
assert-css: (
"//*[@class='result-name']/*[text()='test_docs::']",
{"color": "rgb(255, 255, 255)"},
Expand All @@ -179,7 +179,7 @@ reload:
// Waiting for the search results to appear...
wait-for: "#titles"
assert-css: (
"//*[@class='desc']//*[text()='Just a normal struct.']",
"//*[@class='desc'][text()='Just a normal struct.']",
{"color": "rgb(221, 221, 221)"},
)
assert-css: (
Expand Down Expand Up @@ -276,7 +276,7 @@ reload:
// Waiting for the search results to appear...
wait-for: "#titles"
assert-css: (
"//*[@class='desc']//*[text()='Just a normal struct.']",
"//*[@class='desc'][text()='Just a normal struct.']",
{"color": "rgb(0, 0, 0)"},
)
assert-css: (
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/search-result-display.goml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ press-key: 'Enter'
wait-for: "#crate-search"
// The width is returned by "getComputedStyle" which returns the exact number instead of the
// CSS rule which is "50%"...
assert-css: (".search-results div.desc", {"width": "318px"})
assert-css: (".search-results div.desc", {"width": "310px"})
size: (600, 100)
// As counter-intuitive as it may seem, in this width, the width is "100%", which is why
// when computed it's larger.
Expand Down