From 62658bfc227dee9d8ac4f5d207a8a59bc315977c Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Sat, 12 Jun 2021 22:19:26 -0700 Subject: [PATCH] Open trait implementations' toggles by default. This makes it possible to use Ctrl-F to find methods defined in traits. --- src/librustdoc/html/render/mod.rs | 9 ++------- src/librustdoc/html/static/main.js | 14 +++++++------- .../rustdoc-gui/toggled-open-implementations.goml | 5 +++++ 3 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 src/test/rustdoc-gui/toggled-open-implementations.goml diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 46fe3e2408f39..0efa014b12748 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -488,7 +488,7 @@ fn settings(root_path: &str, suffix: &str, themes: &[StylePath]) -> Result"); - if is_implementing_trait { - write!(w, "
"); - } else { - write!(w, "
"); - } + write!(w, "
"); } if toggled { write!(w, "") diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 1a15a444a701a..e43a231d7570b 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -779,25 +779,25 @@ 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 hideImplementations = getSettingValue("auto-hide-trait-implementations") === "true"; var hideLargeItemContents = getSettingValue("auto-hide-large-items") !== "false"; - function openImplementors(id) { + function setImplementorsTogglesOpen(id, open) { var list = document.getElementById(id); if (list !== null) { onEachLazy(list.getElementsByClassName("implementors-toggle"), function(e) { - e.open = true; + e.open = open; }); } } - if (!hideImplementations) { - openImplementors("trait-implementations-list"); - openImplementors("blanket-implementations-list"); + if (hideImplementations) { + setImplementorsTogglesOpen("trait-implementations-list", false); + setImplementorsTogglesOpen("blanket-implementations-list", false); } if (!hideImplementors) { - openImplementors("implementors-list"); + setImplementorsTogglesOpen("implementors-list", true); } onEachLazy(document.getElementsByClassName("rustdoc-toggle"), function (e) { diff --git a/src/test/rustdoc-gui/toggled-open-implementations.goml b/src/test/rustdoc-gui/toggled-open-implementations.goml new file mode 100644 index 0000000000000..96a5492edefcb --- /dev/null +++ b/src/test/rustdoc-gui/toggled-open-implementations.goml @@ -0,0 +1,5 @@ +// This tests that the "implementations" section on struct/enum pages +// has all the implementations toggled open by default, so users can +// find method names in those implementations with Ctrl-F. +goto: file://|DOC_PATH|/test_docs/struct.Foo.html +assert: (".rustdoc-toggle.implementors-toggle", "open", "")