Skip to content

Commit 15d71d3

Browse files
committed
Rollup merge of #48631 - focusaurus:remember-collapse-setting, r=QuietMisdreavus
Remember state of top-level collapse toggle widget This change allows the big top-right expand/collapse toggle to remember its setting across navigation or page reloads. Prior to this change, there was this annoyance: - browse to some docs - Click the minus button to collapse them - browse to other docs (or reload the page) - Everything is expanded again The solution is based on storing a simple boolean flag in localStorage. I think it's a good improvement, but it does introduce the following potentially surprising behavior: - browse to some docs - click the minus button to collapse them - click to expand a particular item (not the main top-right big one) - reload the page, everything is collapsed Paired with @DebugSteven on this.
2 parents 684c6d1 + 2dd81c8 commit 15d71d3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/librustdoc/html/static/main.js

+6
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,7 @@
16281628
function toggleAllDocs() {
16291629
var toggle = document.getElementById("toggle-all-docs");
16301630
if (hasClass(toggle, "will-expand")) {
1631+
updateLocalStorage("rustdoc-collapse", "false");
16311632
removeClass(toggle, "will-expand");
16321633
onEveryMatchingChild(toggle, "inner", function(e) {
16331634
e.innerHTML = labelForToggleButton(false);
@@ -1637,6 +1638,7 @@
16371638
collapseDocs(e, "show");
16381639
});
16391640
} else {
1641+
updateLocalStorage("rustdoc-collapse", "true");
16401642
addClass(toggle, "will-expand");
16411643
onEveryMatchingChild(toggle, "inner", function(e) {
16421644
e.innerHTML = labelForToggleButton(true);
@@ -1988,6 +1990,10 @@
19881990
window.onresize = function() {
19891991
hideSidebar();
19901992
};
1993+
1994+
if (getCurrentValue("rustdoc-collapse") === "true") {
1995+
toggleAllDocs();
1996+
}
19911997
}());
19921998

19931999
// Sets the focus on the search bar at the top of the page

0 commit comments

Comments
 (0)