Skip to content

Rollup of 6 pull requests #85594

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 13 commits into from
May 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix auto-hide for implementations and implementors.
This sets their toggles to be closed in the HTML (matching the default
setting), and opens them if the setting indicates to do so.

This distinguishes between implementations and implementors based on
being descendants of certain named elements.
  • Loading branch information
jsha committed May 22, 2021
commit 5ebbed6cb02fb4d0272a0b86c500d8f668de321d
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ fn render_impl(
let open_details = |close_tags: &mut String| {
if toggled {
close_tags.insert_str(0, "</details>");
"<details class=\"rustdoc-toggle implementors-toggle\" open><summary>"
"<details class=\"rustdoc-toggle implementors-toggle\"><summary>"
} else {
""
}
Expand Down
25 changes: 21 additions & 4 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,12 +776,29 @@ function hideThemeButtonState() {

var hideMethodDocs = getSettingValue("auto-hide-method-docs") === "true";
var hideImplementors = getSettingValue("auto-collapse-implementors") !== "false";
var hideImplementations = getSettingValue("auto-hide-trait-implementations") !== "false";
var hideLargeItemContents = getSettingValue("auto-hide-large-items") !== "false";

onEachLazy(document.getElementsByTagName("details"), function (e) {
var showLargeItem = !hideLargeItemContents && hasClass(e, "type-contents-toggle");
var showImplementor = !hideImplementors && hasClass(e, "implementors-toggle");
if (showLargeItem || showImplementor) {
function openImplementors(id) {
var list = document.getElementById(id);
if (list !== null) {
onEachLazy(list.getElementsByClassName("implementors-toggle"), function(e) {
e.open = true;
});
}
}

if (!hideImplementations) {
openImplementors("trait-implementations-list");
openImplementors("blanket-implementations-list");
}

if (!hideImplementors) {
openImplementors("implementors-list");
}

onEachLazy(document.getElementsByClassName("rustdoc-toggle"), function (e) {
if (!hideLargeItemContents && hasClass(e, "type-contents-toggle")) {
e.open = true;
}
if (hideMethodDocs && hasClass(e, "method-toggle")) {
Expand Down
3 changes: 2 additions & 1 deletion src/test/rustdoc/manual_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ impl T for S2 {
}

// @has manual_impl/struct.S3.html '//*[@class="trait"]' 'T'
// @has - '//details[@open=""]/div[@class="docblock"]' 'Docs associated with the S3 trait implementation.'
// @has - '//details/div[@class="docblock"]' 'Docs associated with the S3 trait implementation.'
// @!has - '//details[@open=""]/div[@class="docblock"]' 'Docs associated with the S3 trait implementation.'
// @has - '//details[@open=""]/div[@class="docblock"]' 'Docs associated with the S3 trait b_method implementation.'
// @!has - '//div[@class="impl-items"]/details[@open=""]//div[@class="docblock"]' 'Docs associated with the trait a_method definition.'
// @has - '//div[@class="impl-items"]/details//div[@class="docblock"]' 'Docs associated with the trait a_method definition.'
Expand Down