From 33a70981e29119a6fbf22bdca8716825253f5c85 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 25 Apr 2021 14:34:16 +0200 Subject: [PATCH 1/6] Open all impl blocks by default --- src/librustdoc/html/static/main.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 2e3e148eaf695..707eb5a664bd5 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1422,11 +1422,13 @@ function hideThemeButtonState() { // errors in mobile browsers). if (e.tagName === "H2" || e.tagName === "H3") { var nextTagName = e.nextElementSibling.tagName; - if (nextTagName == "H2" || nextTagName == "H3") { + if (nextTagName === "H2" || nextTagName === "H3") { e.nextElementSibling.style.display = "flex"; - } else { + } else if (nextTagName !== "DETAILS") { e.nextElementSibling.style.display = "block"; } + } else if (e.tagName === "DETAILS") { + e.open = true; } }); } From bcad1ec0acea895428a68a86835852e3a01a5a5a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 25 Apr 2021 14:49:43 +0200 Subject: [PATCH 2/6] Add test to ensure that impl blocks are open by default --- src/test/rustdoc-gui/impl-default-expansion.goml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/test/rustdoc-gui/impl-default-expansion.goml diff --git a/src/test/rustdoc-gui/impl-default-expansion.goml b/src/test/rustdoc-gui/impl-default-expansion.goml new file mode 100644 index 0000000000000..686d98f9736e4 --- /dev/null +++ b/src/test/rustdoc-gui/impl-default-expansion.goml @@ -0,0 +1,3 @@ +// This test ensures that the impl blocks are open by default. +goto: file://|DOC_PATH|/struct.Foo.html +assert: ("#main > details.implementors-toggle", "open", "") From 175cd9b1998a8d8202a64c98cf3183cc4197478d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 25 Apr 2021 14:49:29 +0200 Subject: [PATCH 3/6] Remove unneeded rustdoc-gui test because DOM changed --- src/test/rustdoc-gui/nojs-attr-pos.goml | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/test/rustdoc-gui/nojs-attr-pos.goml diff --git a/src/test/rustdoc-gui/nojs-attr-pos.goml b/src/test/rustdoc-gui/nojs-attr-pos.goml deleted file mode 100644 index 35daa4cb9e322..0000000000000 --- a/src/test/rustdoc-gui/nojs-attr-pos.goml +++ /dev/null @@ -1,5 +0,0 @@ -// Check that the attributes are well positioned when javascript is disabled (since -// there is no toggle to display) -javascript: false -goto: file://|DOC_PATH|/struct.Foo.html -assert: (".attributes", {"margin-left": "0px"}) From 1afea79e42f1090d0c565be16442a95f899c6c60 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 25 Apr 2021 15:23:07 +0200 Subject: [PATCH 4/6] Fix expansion for item pointed to by the URL hash --- src/librustdoc/html/static/main.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 707eb5a664bd5..0a348046b1c22 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -480,6 +480,8 @@ function hideThemeButtonState() { } // Open all ancestor
to make this element visible. openParentDetails(h3.parentNode); + } else { + openParentDetails(elem.parentNode); } } } From 9b44c4b29c79edf92a9974d2d72a01c7832e273d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 25 Apr 2021 16:06:42 +0200 Subject: [PATCH 5/6] Add test to ensure that the element pointed to by the URL hash is "expanded" --- src/test/rustdoc-gui/hash-item-expansion.goml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/rustdoc-gui/hash-item-expansion.goml diff --git a/src/test/rustdoc-gui/hash-item-expansion.goml b/src/test/rustdoc-gui/hash-item-expansion.goml new file mode 100644 index 0000000000000..d736d15d184a3 --- /dev/null +++ b/src/test/rustdoc-gui/hash-item-expansion.goml @@ -0,0 +1,18 @@ +// This test ensures that the element corresponding to the hash is displayed. +goto: file://|DOC_PATH|/struct.Foo.html#method.borrow +// In the blanket implementations list, "Borrow" is the second one, hence the ":nth(2)". +assert: ("#blanket-implementations-list > details:nth-child(2)", "open", "") +// Please note the "\" below is needed because otherwise ".borrow" would be interpreted as +// a class selector. +assert: ("#method\.borrow", {"display": "flex"}) +// We first check that the impl block is open by default. +assert: ("#implementations + details", "open", "") +// We collapse it. +click: "#implementations + details > summary" +// We check that it was collapsed as expected. +assert-false: ("#implementations + details", "open", "") +// To ensure that we will click on the currently hidden method. +assert: (".sidebar-links > a", "must_use") +click: ".sidebar-links > a" +// We check that the impl block was opened as expected so that we can see the method. +assert: ("#implementations + details", "open", "") From 6c8969c43ce37d22b0d535ac8fcee1fb6bdb2977 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 26 Apr 2021 10:43:49 +0200 Subject: [PATCH 6/6] Add open attribute on details which are supposed to be open by default instead of opening them with JS --- src/librustdoc/html/render/mod.rs | 4 ++-- src/librustdoc/html/static/main.js | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 67ccf2137bf6e..b82967b403d65 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1305,7 +1305,7 @@ fn render_impl( if let Some(use_absolute) = use_absolute { write!( w, - "
\ + "
\ \

\ ", @@ -1334,7 +1334,7 @@ fn render_impl( } else { write!( w, - "
\ + "
\ \

\ {}", diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 0a348046b1c22..9f7cbca9052d0 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1429,8 +1429,6 @@ function hideThemeButtonState() { } else if (nextTagName !== "DETAILS") { e.nextElementSibling.style.display = "block"; } - } else if (e.tagName === "DETAILS") { - e.open = true; } }); }