Skip to content

Commit 85b45b5

Browse files
authored
Rollup merge of #85575 - jsha:fix-toggle-settings, r=GuillaumeGomez
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. Demo https://hoffman-andrews.com/rust/fix-toggle-settings/std/io/trait.Read.html#implementors and https://hoffman-andrews.com/rust/fix-toggle-settings/std/string/struct.String.html#trait-implementations Fixes #85411 r? `@GuillaumeGomez`
2 parents 75edb76 + 5ebbed6 commit 85b45b5

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/librustdoc/html/render/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ fn render_impl(
15451545
let open_details = |close_tags: &mut String| {
15461546
if toggled {
15471547
close_tags.insert_str(0, "</details>");
1548-
"<details class=\"rustdoc-toggle implementors-toggle\" open><summary>"
1548+
"<details class=\"rustdoc-toggle implementors-toggle\"><summary>"
15491549
} else {
15501550
""
15511551
}

src/librustdoc/html/static/main.js

+21-4
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,29 @@ function hideThemeButtonState() {
776776

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

781-
onEachLazy(document.getElementsByTagName("details"), function (e) {
782-
var showLargeItem = !hideLargeItemContents && hasClass(e, "type-contents-toggle");
783-
var showImplementor = !hideImplementors && hasClass(e, "implementors-toggle");
784-
if (showLargeItem || showImplementor) {
782+
function openImplementors(id) {
783+
var list = document.getElementById(id);
784+
if (list !== null) {
785+
onEachLazy(list.getElementsByClassName("implementors-toggle"), function(e) {
786+
e.open = true;
787+
});
788+
}
789+
}
790+
791+
if (!hideImplementations) {
792+
openImplementors("trait-implementations-list");
793+
openImplementors("blanket-implementations-list");
794+
}
795+
796+
if (!hideImplementors) {
797+
openImplementors("implementors-list");
798+
}
799+
800+
onEachLazy(document.getElementsByClassName("rustdoc-toggle"), function (e) {
801+
if (!hideLargeItemContents && hasClass(e, "type-contents-toggle")) {
785802
e.open = true;
786803
}
787804
if (hideMethodDocs && hasClass(e, "method-toggle")) {

src/test/rustdoc/manual_impl.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ impl T for S2 {
6565
}
6666

6767
// @has manual_impl/struct.S3.html '//*[@class="trait"]' 'T'
68-
// @has - '//details[@open=""]/div[@class="docblock"]' 'Docs associated with the S3 trait implementation.'
68+
// @has - '//details/div[@class="docblock"]' 'Docs associated with the S3 trait implementation.'
69+
// @!has - '//details[@open=""]/div[@class="docblock"]' 'Docs associated with the S3 trait implementation.'
6970
// @has - '//details[@open=""]/div[@class="docblock"]' 'Docs associated with the S3 trait b_method implementation.'
7071
// @!has - '//div[@class="impl-items"]/details[@open=""]//div[@class="docblock"]' 'Docs associated with the trait a_method definition.'
7172
// @has - '//div[@class="impl-items"]/details//div[@class="docblock"]' 'Docs associated with the trait a_method definition.'

0 commit comments

Comments
 (0)