Skip to content

Commit d3c37b1

Browse files
+/- shortcut now only expand/collapse, not both
1 parent 4b3b731 commit d3c37b1

File tree

1 file changed

+30
-29
lines changed
  • src/librustdoc/html/static/js

1 file changed

+30
-29
lines changed

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

+30-29
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,12 @@ function loadCss(cssFileName) {
409409
break;
410410

411411
case "+":
412+
ev.preventDefault();
413+
expandAllDocs();
414+
break;
412415
case "-":
413416
ev.preventDefault();
414-
toggleAllDocs();
417+
collapseAllDocs();
415418
break;
416419

417420
case "?":
@@ -614,45 +617,43 @@ function loadCss(cssFileName) {
614617
sidebarElems.appendChild(ul);
615618
}
616619

620+
function expandAllDocs() {
621+
const innerToggle = document.getElementById(toggleAllDocsId);
622+
removeClass(innerToggle, "will-expand");
623+
onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
624+
if (!hasClass(e, "type-contents-toggle")) {
625+
e.open = true;
626+
}
627+
});
628+
innerToggle.title = "collapse all docs";
629+
innerToggle.children[0].innerText = "\u2212"; // "\u2212" is "−" minus sign
630+
}
617631

618-
function labelForToggleButton(sectionIsCollapsed) {
619-
if (sectionIsCollapsed) {
620-
// button will expand the section
621-
return "+";
622-
}
623-
// button will collapse the section
624-
// note that this text is also set in the HTML template in ../render/mod.rs
625-
return "\u2212"; // "\u2212" is "−" minus sign
632+
function collapseAllDocs() {
633+
const innerToggle = document.getElementById(toggleAllDocsId);
634+
addClass(innerToggle, "will-expand");
635+
onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
636+
if (e.parentNode.id !== "implementations-list" ||
637+
(!hasClass(e, "implementors-toggle") &&
638+
!hasClass(e, "type-contents-toggle"))
639+
) {
640+
e.open = false;
641+
}
642+
});
643+
innerToggle.title = "expand all docs";
644+
innerToggle.children[0].innerText = "+";
626645
}
627646

628647
function toggleAllDocs() {
629648
const innerToggle = document.getElementById(toggleAllDocsId);
630649
if (!innerToggle) {
631650
return;
632651
}
633-
let sectionIsCollapsed = false;
634652
if (hasClass(innerToggle, "will-expand")) {
635-
removeClass(innerToggle, "will-expand");
636-
onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
637-
if (!hasClass(e, "type-contents-toggle")) {
638-
e.open = true;
639-
}
640-
});
641-
innerToggle.title = "collapse all docs";
653+
expandAllDocs();
642654
} else {
643-
addClass(innerToggle, "will-expand");
644-
onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
645-
if (e.parentNode.id !== "implementations-list" ||
646-
(!hasClass(e, "implementors-toggle") &&
647-
!hasClass(e, "type-contents-toggle"))
648-
) {
649-
e.open = false;
650-
}
651-
});
652-
sectionIsCollapsed = true;
653-
innerToggle.title = "expand all docs";
655+
collapseAllDocs();
654656
}
655-
innerToggle.children[0].innerText = labelForToggleButton(sectionIsCollapsed);
656657
}
657658

658659
(function() {

0 commit comments

Comments
 (0)