Skip to content
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

Add option to collapse automatically implementors #74196

Merged
merged 2 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1289,8 +1289,9 @@ fn settings(root_path: &str, suffix: &str) -> String {
.into(),
("auto-hide-attributes", "Auto-hide item attributes.", true).into(),
Copy link
Member

Choose a reason for hiding this comment

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

overall i think we might need to fix up the language used for all these settings in a separate issue, it seems very unclear (cc @jyn514 thoughts?)

Copy link
Member

Choose a reason for hiding this comment

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

It's not terribly clear but it does say exactly what it does (attributes is the technical term for #[some_macro], right?). I think it would be helpful to have screenshots before and after, then it's very clear to see.

Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking of the entire set of names, not just this one, though. This one is kinda fine.

("auto-hide-method-docs", "Auto-hide item methods' documentation", false).into(),
("auto-hide-trait-implementations", "Auto-hide trait implementations documentation", true)
("auto-hide-trait-implementations", "Auto-hide trait implementation documentation", true)
.into(),
("auto-collapse-implementors", "Auto-hide implementors of a trait", true).into(),
("go-to-only-result", "Directly go to item in search if there is only one result", false)
.into(),
("line-numbers", "Show line numbers on code examples", false).into(),
Expand Down
12 changes: 9 additions & 3 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2241,8 +2241,7 @@ function defocusSearchBar() {
relatedDoc = relatedDoc.nextElementSibling;
}

if ((!relatedDoc && hasClass(docblock, "docblock") === false) ||
(pageId && document.getElementById(pageId))) {
if (!relatedDoc && hasClass(docblock, "docblock") === false) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Little note about this change for the reviewers: it was to prevent an element targetted by the url hash (so #variant.X for example) to be hidden. However, it has been long fixed and this code wasn't removed. And this case, it was a big issue in case you had #implementors as page id because then it prevented the impl blocks to be collapsed. I tested without this check for all other cases and it works fine.

return;
}

Expand Down Expand Up @@ -2362,6 +2361,7 @@ function defocusSearchBar() {
(function() {
var toggle = createSimpleToggle(false);
var hideMethodDocs = getCurrentValue("rustdoc-auto-hide-method-docs") === "true";
var hideImplementors = getCurrentValue("rustdoc-auto-collapse-implementors") !== "false";
Copy link
Member

Choose a reason for hiding this comment

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

Just curious - why do these use strings instead of true and false?

Copy link
Member Author

Choose a reason for hiding this comment

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

When you use the local storage, it converts everything to string. As simple as that. :)

var pageId = getPageId();

var func = function(e) {
Expand Down Expand Up @@ -2391,7 +2391,13 @@ function defocusSearchBar() {
if (hasClass(e, "impl") &&
(next.getElementsByClassName("method").length > 0 ||
next.getElementsByClassName("associatedconstant").length > 0)) {
insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]);
var newToggle = toggle.cloneNode(true);
insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
// In case the option "auto-collapse implementors" is not set to false, we collapse
// all implementors.
if (hideImplementors === true && e.parentNode.id === "implementors-list") {
collapseDocs(newToggle, "hide", pageId);
}
}
};

Expand Down