Skip to content

Commit 970174a

Browse files
Add option to collapse automatically implementors
1 parent f844ea1 commit 970174a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/librustdoc/html/render.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,7 @@ fn settings(root_path: &str, suffix: &str) -> String {
12911291
("auto-hide-method-docs", "Auto-hide item methods' documentation", false).into(),
12921292
("auto-hide-trait-implementations", "Auto-hide trait implementations documentation", true)
12931293
.into(),
1294+
("auto-collapse-implementors", "Auto-collapse implementors", true).into(),
12941295
("go-to-only-result", "Directly go to item in search if there is only one result", false)
12951296
.into(),
12961297
("line-numbers", "Show line numbers on code examples", false).into(),

src/librustdoc/html/static/main.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,8 +2241,7 @@ function defocusSearchBar() {
22412241
relatedDoc = relatedDoc.nextElementSibling;
22422242
}
22432243

2244-
if ((!relatedDoc && hasClass(docblock, "docblock") === false) ||
2245-
(pageId && document.getElementById(pageId))) {
2244+
if (!relatedDoc && hasClass(docblock, "docblock") === false) {
22462245
return;
22472246
}
22482247

@@ -2362,6 +2361,7 @@ function defocusSearchBar() {
23622361
(function() {
23632362
var toggle = createSimpleToggle(false);
23642363
var hideMethodDocs = getCurrentValue("rustdoc-auto-hide-method-docs") === "true";
2364+
var hideImplementors = getCurrentValue("rustdoc-auto-collapse-implementors") !== "false";
23652365
var pageId = getPageId();
23662366

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

0 commit comments

Comments
 (0)