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 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
1 change: 1 addition & 0 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,7 @@ fn settings(root_path: &str, suffix: &str) -> String {
("auto-hide-method-docs", "Auto-hide item methods' documentation", false).into(),
("auto-hide-trait-implementations", "Auto-hide trait implementations documentation", true)
.into(),
("auto-collapse-implementors", "Auto-collapse implementors", 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.

I think this is confusing, I wonder if we can just merge this with the previous option?

Or perhaps two settings:

  • Auto-hide trait implementation documentation
  • Auto-hide trait implementation items

Copy link
Member Author

Choose a reason for hiding this comment

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

Hum... Maybe a rewording? But I think it'd be nice trying to make settings more obvious more generally. In this case, we target just the implementors (the section and its children), not the trait implementations generally.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I just think that when you have so many it gets confusing. Definitely when I look at the page I'm unsure as to what some of the options do.

Rewording seems fine

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm open to suggestions then! Btw: should I do it in this PR directly or should I open a new one?

Copy link
Member

Choose a reason for hiding this comment

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

Do it here itself. I suggested options for the wording above for the two settings

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh indeed! Thanks, sending an update shortly.

("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