-
Notifications
You must be signed in to change notification settings - Fork 13.4k
rustdoc: Foldable impl blocks #47894
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
Changes from 2 commits
73f52d3
7cd0280
c904b1b
0885865
a3acd10
28efcfc
bc277b2
71c4da8
6442580
3c83596
bf03dd0
df1b9a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -296,9 +296,9 @@ | |
document.onkeydown = handleShortcut; | ||
document.onclick = function(ev) { | ||
if (hasClass(ev.target, 'collapse-toggle')) { | ||
collapseDocs(ev.target); | ||
collapseDocs(ev.target, "toggle"); | ||
} else if (hasClass(ev.target.parentNode, 'collapse-toggle')) { | ||
collapseDocs(ev.target.parentNode); | ||
collapseDocs(ev.target.parentNode, "toggle"); | ||
} else if (ev.target.tagName === 'SPAN' && hasClass(ev.target.parentNode, 'line-numbers')) { | ||
var prev_id = 0; | ||
|
||
|
@@ -1618,74 +1618,124 @@ | |
e.innerHTML = labelForToggleButton(false); | ||
}); | ||
toggle.title = "collapse all docs"; | ||
onEach(document.getElementsByClassName("docblock"), function(e) { | ||
e.style.display = 'block'; | ||
}); | ||
onEach(document.getElementsByClassName("toggle-label"), function(e) { | ||
e.style.display = 'none'; | ||
}); | ||
onEach(document.getElementsByClassName("toggle-wrapper"), function(e) { | ||
removeClass(e, "collapsed"); | ||
}); | ||
onEach(document.getElementsByClassName("collapse-toggle"), function(e) { | ||
onEveryMatchingChild(e, "inner", function(i_e) { | ||
i_e.innerHTML = labelForToggleButton(false); | ||
}); | ||
collapseDocs(e, "show"); | ||
}); | ||
} else { | ||
addClass(toggle, "will-expand"); | ||
onEveryMatchingChild(toggle, "inner", function(e) { | ||
e.innerHTML = labelForToggleButton(true); | ||
}); | ||
toggle.title = "expand all docs"; | ||
onEach(document.getElementsByClassName("docblock"), function(e) { | ||
e.style.display = 'none'; | ||
}); | ||
onEach(document.getElementsByClassName("toggle-label"), function(e) { | ||
e.style.display = 'inline-block'; | ||
}); | ||
onEach(document.getElementsByClassName("toggle-wrapper"), function(e) { | ||
addClass(e, "collapsed"); | ||
}); | ||
|
||
onEach(document.getElementsByClassName("collapse-toggle"), function(e) { | ||
onEveryMatchingChild(e, "inner", function(i_e) { | ||
i_e.innerHTML = labelForToggleButton(true); | ||
}); | ||
collapseDocs(e, "hide"); | ||
}); | ||
} | ||
} | ||
|
||
function collapseDocs(toggle) { | ||
function collapseDocs(toggle, mode) { | ||
if (!toggle || !toggle.parentNode) { | ||
return; | ||
} | ||
var relatedDoc = toggle.parentNode.nextElementSibling; | ||
if (hasClass(relatedDoc, "stability")) { | ||
relatedDoc = relatedDoc.nextElementSibling; | ||
} | ||
if (hasClass(relatedDoc, "docblock")) { | ||
if (!isHidden(relatedDoc)) { | ||
relatedDoc.style.display = 'none'; | ||
onEach(toggle.childNodes, function(e) { | ||
if (hasClass(e, 'toggle-label')) { | ||
|
||
function adjustToggle(arg) { | ||
return function(e) { | ||
if (hasClass(e, 'toggle-label')) { | ||
if (arg) { | ||
e.style.display = 'inline-block'; | ||
} | ||
if (hasClass(e, 'inner')) { | ||
e.innerHTML = labelForToggleButton(true); | ||
} | ||
}); | ||
addClass(toggle.parentNode, 'collapsed'); | ||
} else { | ||
relatedDoc.style.display = 'block'; | ||
removeClass(toggle.parentNode, 'collapsed'); | ||
onEach(toggle.childNodes, function(e) { | ||
if (hasClass(e, 'toggle-label')) { | ||
} else { | ||
e.style.display = 'none'; | ||
} | ||
if (hasClass(e, 'inner')) { | ||
e.innerHTML = labelForToggleButton(false); | ||
} | ||
if (hasClass(e, 'inner')) { | ||
e.innerHTML = labelForToggleButton(arg); | ||
} | ||
}; | ||
}; | ||
|
||
if (!hasClass(toggle.parentNode, "impl")) { | ||
var relatedDoc = toggle.parentNode.nextElementSibling; | ||
if (hasClass(relatedDoc, "stability")) { | ||
relatedDoc = relatedDoc.nextElementSibling; | ||
} | ||
if (hasClass(relatedDoc, "docblock")) { | ||
var action = mode; | ||
if (action == "toggle") { | ||
if(hasClass(relatedDoc, "hidden-by-usual-hider")) { | ||
action="show"; | ||
} else { | ||
action="hide"; | ||
} | ||
}); | ||
} | ||
if (action == "hide") { | ||
addClass(relatedDoc, "hidden-by-usual-hider"); | ||
onEach(toggle.childNodes, adjustToggle(true)); | ||
addClass(toggle.parentNode, 'collapsed'); | ||
} else if (action == "show") { | ||
removeClass(relatedDoc, "hidden-by-usual-hider"); | ||
removeClass(toggle.parentNode, 'collapsed'); | ||
onEach(toggle.childNodes, adjustToggle(false)); | ||
} | ||
} | ||
} else { | ||
// we are collapsing the impl block | ||
function implHider(addOrRemove) { | ||
return function(n) { | ||
if(hasClass(n, "method")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing whitespace after |
||
if (addOrRemove) { | ||
addClass(n, "hidden-by-impl-hider"); | ||
} else { | ||
removeClass(n, "hidden-by-impl-hider"); | ||
} | ||
var ns = n.nextElementSibling; | ||
while(true) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing whitespace after |
||
if (ns && ( | ||
hasClass(ns, "docblock") || | ||
hasClass(ns, "stability") || | ||
false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this line?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To keep the list open and allow 1-line diffs for removals and additions of classes. To avoid the first or last mentioned class being special (by not having |
||
)) { | ||
if (addOrRemove) { | ||
addClass(ns, "hidden-by-impl-hider"); | ||
} else { | ||
removeClass(ns, "hidden-by-impl-hider"); | ||
} | ||
ns = ns.nextElementSibling; | ||
continue; | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
var relatedDoc = toggle.parentNode; | ||
|
||
while (!hasClass(relatedDoc, "impl-items")) { | ||
relatedDoc = relatedDoc.nextElementSibling; | ||
} | ||
|
||
if (!relatedDoc) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't do that. Use |
||
|
||
// Hide all functions, but not associated types/consts | ||
|
||
var action = mode; | ||
if (action == "toggle") { | ||
if(hasClass(relatedDoc, "fns-now-collapsed")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing whitespace after |
||
action="show"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing whitespace around |
||
} else { | ||
action="hide"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing whitespace around |
||
} | ||
} | ||
|
||
if(action == "show") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing whitespace after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, please use |
||
removeClass(relatedDoc, "fns-now-collapsed"); | ||
onEach(toggle.childNodes, adjustToggle(false)); | ||
onEach(relatedDoc.childNodes, implHider(false)); | ||
} else if (action == "hide") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
addClass(relatedDoc, "fns-now-collapsed"); | ||
onEach(toggle.childNodes, adjustToggle(true)); | ||
onEach(relatedDoc.childNodes, implHider(true)); | ||
} | ||
} | ||
} | ||
|
@@ -1714,8 +1764,12 @@ | |
hasClass(next.nextElementSibling, 'docblock'))) { | ||
insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]); | ||
} | ||
if (hasClass(e, 'impl')) { | ||
insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]); | ||
} | ||
} | ||
onEach(document.getElementsByClassName('method'), func); | ||
onEach(document.getElementsByClassName('impl'), func); | ||
onEach(document.getElementsByClassName('impl-items'), function(e) { | ||
onEach(e.getElementsByClassName('associatedconstant'), func); | ||
}); | ||
|
@@ -1803,7 +1857,7 @@ | |
onEach(document.getElementById('main').getElementsByTagName('pre'), function(e) { | ||
onEach(e.getElementsByClassName('attributes'), function(i_e) { | ||
i_e.parentNode.insertBefore(createToggleWrapper(), i_e); | ||
collapseDocs(i_e.previousSibling.childNodes[0]); | ||
collapseDocs(i_e.previousSibling.childNodes[0], "toggle"); | ||
}); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -386,3 +386,8 @@ kbd { | |
background: #353535; | ||
} | ||
} | ||
|
||
.hidden-by-impl-hider, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This rule has nothing to do in themes. Please put in |
||
.hidden-by-usual-hider { | ||
display: none; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -383,3 +383,8 @@ kbd { | |
background: #fff; | ||
} | ||
} | ||
|
||
.hidden-by-impl-hider, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This rule has nothing to do in themes. Please put in |
||
.hidden-by-usual-hider { | ||
display: none; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing whitespace after
if
.