Skip to content

Commit efad203

Browse files
authoredJul 15, 2020
Rollup merge of #74196 - GuillaumeGomez:auto-collapse-implementors, r=Manishearth
Add option to collapse automatically implementors Fixes #73403 It adds an option (enabled by default) which collapses all implementors impl blocks. r? @kinnison cc @rust-lang/rustdoc
2 parents 0bb16c8 + 39d99ea commit efad203

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed
 

‎src/librustdoc/html/render.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1322,8 +1322,9 @@ fn settings(root_path: &str, suffix: &str) -> String {
13221322
.into(),
13231323
("auto-hide-attributes", "Auto-hide item attributes.", true).into(),
13241324
("auto-hide-method-docs", "Auto-hide item methods' documentation", false).into(),
1325-
("auto-hide-trait-implementations", "Auto-hide trait implementations documentation", true)
1325+
("auto-hide-trait-implementations", "Auto-hide trait implementation documentation", true)
13261326
.into(),
1327+
("auto-collapse-implementors", "Auto-hide implementors of a trait", true).into(),
13271328
("go-to-only-result", "Directly go to item in search if there is only one result", false)
13281329
.into(),
13291330
("line-numbers", "Show line numbers on code examples", false).into(),

‎src/librustdoc/html/static/main.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -2243,8 +2243,7 @@ function defocusSearchBar() {
22432243
relatedDoc = relatedDoc.nextElementSibling;
22442244
}
22452245

2246-
if ((!relatedDoc && hasClass(docblock, "docblock") === false) ||
2247-
(pageId && document.getElementById(pageId))) {
2246+
if (!relatedDoc && hasClass(docblock, "docblock") === false) {
22482247
return;
22492248
}
22502249

@@ -2364,6 +2363,7 @@ function defocusSearchBar() {
23642363
(function() {
23652364
var toggle = createSimpleToggle(false);
23662365
var hideMethodDocs = getCurrentValue("rustdoc-auto-hide-method-docs") === "true";
2366+
var hideImplementors = getCurrentValue("rustdoc-auto-collapse-implementors") !== "false";
23672367
var pageId = getPageId();
23682368

23692369
var func = function(e) {
@@ -2393,7 +2393,13 @@ function defocusSearchBar() {
23932393
if (hasClass(e, "impl") &&
23942394
(next.getElementsByClassName("method").length > 0 ||
23952395
next.getElementsByClassName("associatedconstant").length > 0)) {
2396-
insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]);
2396+
var newToggle = toggle.cloneNode(true);
2397+
insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
2398+
// In case the option "auto-collapse implementors" is not set to false, we collapse
2399+
// all implementors.
2400+
if (hideImplementors === true && e.parentNode.id === "implementors-list") {
2401+
collapseDocs(newToggle, "hide", pageId);
2402+
}
23972403
}
23982404
};
23992405

0 commit comments

Comments
 (0)
Please sign in to comment.