Skip to content

rustdoc: make expand/collapse all ephemeral #84325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
rustdoc: make expand/collapse all ephemeral
The `[+]` in the upper right of a rustdoc page expands or collapses all
toggles on the page. That state is stored across page loads, but is used
inconsistently. This change explicitly stops storing or using the state.
  • Loading branch information
jsha committed Apr 19, 2021
commit 39b299f8a46fd3c2467a61ce7a5b9829ce03fc7d
44 changes: 17 additions & 27 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,6 @@ function hideThemeButtonState() {
return;
}
if (hasClass(innerToggle, "will-expand")) {
updateLocalStorage("rustdoc-collapse", "false");
removeClass(innerToggle, "will-expand");
onEachLazy(document.getElementsByTagName("details"), function(e) {
e.open = true;
Expand All @@ -920,7 +919,6 @@ function hideThemeButtonState() {
});
}
} else {
updateLocalStorage("rustdoc-collapse", "true");
addClass(innerToggle, "will-expand");
onEachLazy(document.getElementsByTagName("details"), function(e) {
e.open = false;
Expand Down Expand Up @@ -1075,7 +1073,7 @@ function hideThemeButtonState() {
}
}

function collapser(e, collapse) {
function collapseNonInherent(e, collapse) {
// inherent impl ids are like "impl" or impl-<number>'.
// they will never be hidden by default.
var n = e.parentElement;
Expand All @@ -1087,28 +1085,6 @@ function hideThemeButtonState() {
}
}

function autoCollapse(collapse) {
if (collapse) {
toggleAllDocs(true);
} else if (getSettingValue("auto-hide-trait-implementations") !== "false") {
var impl_list = document.getElementById("trait-implementations-list");

if (impl_list !== null) {
onEachLazy(impl_list.getElementsByClassName("collapse-toggle"), function(e) {
collapser(e, collapse);
});
}

var blanket_list = document.getElementById("blanket-implementations-list");

if (blanket_list !== null) {
onEachLazy(blanket_list.getElementsByClassName("collapse-toggle"), function(e) {
collapser(e, collapse);
});
}
}
}

function insertAfter(newNode, referenceNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}
Expand Down Expand Up @@ -1167,6 +1143,22 @@ function hideThemeButtonState() {
var hideMethodDocs = getSettingValue("auto-hide-method-docs") === "true";
var hideImplementors = getSettingValue("auto-collapse-implementors") !== "false";
var hideLargeItemContents = getSettingValue("auto-hide-large-items") !== "false";
var hideTraitImplementations =
getSettingValue("auto-hide-trait-implementations") !== "false";

var impl_list = document.getElementById("trait-implementations-list");
if (impl_list !== null) {
onEachLazy(impl_list.getElementsByClassName("collapse-toggle"), function(e) {
collapseNonInherent(e, collapse);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this collapse coming from?

});
}

var blanket_list = document.getElementById("blanket-implementations-list");
if (blanket_list !== null) {
onEachLazy(blanket_list.getElementsByClassName("collapse-toggle"), function(e) {
collapseNonInherent(e, collapse);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this collapse coming from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting. This was a leftover param that was only true when getSettingValue("collapse") === "true". That was never the case, because "collapse" was the wrong setting name anyhow ("rustdoc-collapse" was the right setting name). Removed it.

});
}

var func = function(e) {
var next = e.nextElementSibling;
Expand Down Expand Up @@ -1353,8 +1345,6 @@ function hideThemeButtonState() {
onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);

autoCollapse(getSettingValue("collapse") === "true");

var pageId = getPageId();
if (pageId !== null) {
expandSection(pageId);
Expand Down