Skip to content

Commit fc61cca

Browse files
Expand sub code blocks block content when hidden when the page hash refers to it
1 parent 0fcb7da commit fc61cca

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/librustdoc/html/static/main.js

+8
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,14 @@ function defocusSearchBar() {
306306
function expandSection(id) {
307307
var elem = document.getElementById(id);
308308
if (elem && isHidden(elem)) {
309+
if (elem.tagName === "CODE" && elem.parentNode.tagName === "H4") {
310+
// We are in a trait implementation, what we want is the parent.
311+
elem = elem.parentNode;
312+
if (elem.id !== null && elem.id.length > 0) {
313+
// Change the id to the parent which is "more clear" and better for users.
314+
window.location.hash = elem.id;
315+
}
316+
}
309317
var h3 = elem.parentNode.previousElementSibling;
310318
if (h3 && h3.tagName !== "H3") {
311319
h3 = h3.previousElementSibling; // skip div.docblock

0 commit comments

Comments
 (0)