From 970174a1e5d45f82608fdc220de99f34eccb2008 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 9 Jul 2020 21:42:02 +0200 Subject: [PATCH 1/2] Add option to collapse automatically implementors --- src/librustdoc/html/render.rs | 1 + src/librustdoc/html/static/main.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 04c4685213b2e..17c1d1c7fd6de 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1291,6 +1291,7 @@ fn settings(root_path: &str, suffix: &str) -> String { ("auto-hide-method-docs", "Auto-hide item methods' documentation", false).into(), ("auto-hide-trait-implementations", "Auto-hide trait implementations documentation", true) .into(), + ("auto-collapse-implementors", "Auto-collapse implementors", true).into(), ("go-to-only-result", "Directly go to item in search if there is only one result", false) .into(), ("line-numbers", "Show line numbers on code examples", false).into(), diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 62a23298c1b9f..9db9d5bb891a0 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -2241,8 +2241,7 @@ function defocusSearchBar() { relatedDoc = relatedDoc.nextElementSibling; } - if ((!relatedDoc && hasClass(docblock, "docblock") === false) || - (pageId && document.getElementById(pageId))) { + if (!relatedDoc && hasClass(docblock, "docblock") === false) { return; } @@ -2362,6 +2361,7 @@ function defocusSearchBar() { (function() { var toggle = createSimpleToggle(false); var hideMethodDocs = getCurrentValue("rustdoc-auto-hide-method-docs") === "true"; + var hideImplementors = getCurrentValue("rustdoc-auto-collapse-implementors") !== "false"; var pageId = getPageId(); var func = function(e) { @@ -2391,7 +2391,13 @@ function defocusSearchBar() { if (hasClass(e, "impl") && (next.getElementsByClassName("method").length > 0 || next.getElementsByClassName("associatedconstant").length > 0)) { - insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]); + var newToggle = toggle.cloneNode(true); + insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]); + // In case the option "auto-collapse implementors" is not set to false, we collapse + // all implementors. + if (hideImplementors === true && e.parentNode.id === "implementors-list") { + collapseDocs(newToggle, "hide", pageId); + } } }; From 39d99ea6e600e37678275b0ca74b70bf93512154 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 9 Jul 2020 22:51:04 +0200 Subject: [PATCH 2/2] Improve settings wording --- src/librustdoc/html/render.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 17c1d1c7fd6de..5dcd9ebbdd09b 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1289,9 +1289,9 @@ fn settings(root_path: &str, suffix: &str) -> String { .into(), ("auto-hide-attributes", "Auto-hide item attributes.", true).into(), ("auto-hide-method-docs", "Auto-hide item methods' documentation", false).into(), - ("auto-hide-trait-implementations", "Auto-hide trait implementations documentation", true) + ("auto-hide-trait-implementations", "Auto-hide trait implementation documentation", true) .into(), - ("auto-collapse-implementors", "Auto-collapse implementors", true).into(), + ("auto-collapse-implementors", "Auto-hide implementors of a trait", true).into(), ("go-to-only-result", "Directly go to item in search if there is only one result", false) .into(), ("line-numbers", "Show line numbers on code examples", false).into(),