Skip to content

Fix results search alias display #113823

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

Merged
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
5 changes: 4 additions & 1 deletion src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ so that we can apply CSS-filters to change the arrow color in themes */
justify-content: start;
flex: 3;
}
.search-results .result-name span.alias {
.search-results .result-name .alias {
color: var(--search-results-alias-color);
}
.search-results .result-name .grey {
Expand All @@ -904,6 +904,9 @@ so that we can apply CSS-filters to change the arrow color in themes */
max-width: calc(100% - var(--search-typename-width));
display: inline-block;
}
.search-results .result-name .path > * {
display: inline;
}

.popover {
position: absolute;
Expand Down
29 changes: 11 additions & 18 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2108,29 +2108,22 @@ function initSearch(rawSearchIndex) {
const resultName = document.createElement("div");
resultName.className = "result-name";

if (item.is_alias) {
const alias = document.createElement("span");
alias.className = "alias";

const bold = document.createElement("b");
bold.innerText = item.alias;
alias.appendChild(bold);

alias.insertAdjacentHTML(
"beforeend",
"<i class=\"grey\">&nbsp;- see&nbsp;</i>");
resultName.insertAdjacentHTML(
"beforeend",
`<span class="typename">${typeName}</span>`);
link.appendChild(resultName);

resultName.appendChild(alias);
let alias = " ";
if (item.is_alias) {
alias = ` <div class="alias">\
<b>${item.alias}</b><i class="grey">&nbsp;- see&nbsp;</i>\
</div>`;
}

resultName.insertAdjacentHTML(
"beforeend",
`\
<span class="typename">${typeName}</span>\
<div class="path">\
${item.displayPath}<span class="${type}">${name}</span>\
`<div class="path">${alias}\
${item.displayPath}<span class="${type}">${name}</span>\
</div>`);
link.appendChild(resultName);

const description = document.createElement("div");
description.className = "desc";
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc-gui/search-reexport.goml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ write: (".search-input", "AliasForTheStdReexport")
wait-for: "//a[@class='result-import']"
assert-text: (
"a.result-import .result-name",
"AliasForTheStdReexport - see re-export test_docs::TheStdReexport",
"re-export AliasForTheStdReexport - see test_docs::TheStdReexport",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite funny that we didn't realize with this test that something was really wrong. XD

)
// Same thing again, we click on it to ensure the background is once again set as expected.
click: "//a[@class='result-import']"
Expand Down
4 changes: 2 additions & 2 deletions tests/rustdoc-gui/search-result-color.goml
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ define-function: (
// Waiting for the search results to appear...
wait-for: "#search-tabs"
// Checking that the colors for the alias element are the ones expected.
assert-css: (".result-name > .alias", {"color": |alias|})
assert-css: (".result-name > .alias > .grey", {"color": |grey|})
assert-css: (".result-name .path .alias", {"color": |alias|})
assert-css: (".result-name .path .alias > .grey", {"color": |grey|})
// Leave the search results to prevent reloading with an already filled search input.
press-key: "Escape"
},
Expand Down