Auto merge of #51527 - kennytm:do-not-auto-hide-inherent-impl, r=GuillaumeGomez

Don't auto-hide inherent impls even if `rustdoc-collapse == true`.

This PR changes the auto-collapse behavior when a page is first loaded:

* Inherent impls will never be collapsed by default (new behavior).
* Trait impls will always be collapsed by default, same as before.
* Other items are collapsed according to localStorage, same as before.

This should be much more useful since there is no hint what the content of a collapsed inherent impl would be (try to collapse everything in https://doc.rust-lang.org/std/vec/struct.Vec.html and guess where a method like `try_reserve` or `splice` would be).

Manually clicking the global [-]/[+] will still collapse/expand everything.
This commit is contained in:
bors 2018-06-13 10:03:05 +00:00
commit 7f20af002e

View File

@ -1775,7 +1775,7 @@
} }
} }
function toggleAllDocs(pageId) { function toggleAllDocs(pageId, fromAutoCollapse) {
var toggle = document.getElementById("toggle-all-docs"); var toggle = document.getElementById("toggle-all-docs");
if (!toggle) { if (!toggle) {
return; return;
@ -1787,9 +1787,11 @@
e.innerHTML = labelForToggleButton(false); e.innerHTML = labelForToggleButton(false);
}); });
toggle.title = "collapse all docs"; toggle.title = "collapse all docs";
onEach(document.getElementsByClassName("collapse-toggle"), function(e) { if (fromAutoCollapse !== true) {
collapseDocs(e, "show"); onEach(document.getElementsByClassName("collapse-toggle"), function(e) {
}); collapseDocs(e, "show");
});
}
} else { } else {
updateLocalStorage("rustdoc-collapse", "true"); updateLocalStorage("rustdoc-collapse", "true");
addClass(toggle, "will-expand"); addClass(toggle, "will-expand");
@ -1797,10 +1799,11 @@
e.innerHTML = labelForToggleButton(true); e.innerHTML = labelForToggleButton(true);
}); });
toggle.title = "expand all docs"; toggle.title = "expand all docs";
if (fromAutoCollapse !== true) {
onEach(document.getElementsByClassName("collapse-toggle"), function(e) { onEach(document.getElementsByClassName("collapse-toggle"), function(e) {
collapseDocs(e, "hide", pageId); collapseDocs(e, "hide", pageId);
}); });
}
} }
} }
@ -1921,17 +1924,19 @@
} }
} }
function autoCollapseAllImpls(pageId) { function autoCollapse(pageId, collapse) {
// Automatically minimize all non-inherent impls if (collapse) {
onEach(document.getElementsByClassName('impl'), function(n) { toggleAllDocs(pageId, true);
// inherent impl ids are like 'impl' or impl-<number>' }
var inherent = (n.id.match(/^impl(?:-\d+)?$/) !== null); onEach(document.getElementsByClassName("collapse-toggle"), function(e) {
if (!inherent) { // inherent impl ids are like 'impl' or impl-<number>'.
onEach(n.childNodes, function(m) { // they will never be hidden by default.
if (hasClass(m, "collapse-toggle")) { var n = e.parentNode;
collapseDocs(m, "hide", pageId); if (n.id.match(/^impl(?:-\d+)?$/) === null) {
} // Automatically minimize all non-inherent impls
}); if (collapse || hasClass(n, 'impl')) {
collapseDocs(e, "hide", pageId);
}
} }
}); });
} }
@ -2044,8 +2049,6 @@
} }
}); });
autoCollapseAllImpls(getPageId());
function createToggleWrapper(tog) { function createToggleWrapper(tog) {
var span = document.createElement('span'); var span = document.createElement('span');
span.className = 'toggle-label'; span.className = 'toggle-label';
@ -2175,9 +2178,7 @@
hideSidebar(); hideSidebar();
}; };
if (getCurrentValue("rustdoc-collapse") === "true") { autoCollapse(getPageId(), getCurrentValue("rustdoc-collapse") === "true");
toggleAllDocs(getPageId());
}
}()); }());
// Sets the focus on the search bar at the top of the page // Sets the focus on the search bar at the top of the page