Skip to content

Commit 0e29085

Browse files
committed
rustdoc: add private items toggle
1 parent c79bbfa commit 0e29085

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

src/librustdoc/html/render/print_item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,9 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i
479479
Some(ty::Visibility::Restricted(_)) => {
480480
if myitem.is_doc_hidden() {
481481
// Don't separate with a space when there are two of them
482-
"<span title=\"Restricted Visibility\">&nbsp;🔒</span><span title=\"Hidden item\">👻</span> "
482+
"<span class=\"priv-item\" title=\"Restricted Visibility\">&nbsp;🔒</span><span title=\"Hidden item\">👻</span> "
483483
} else {
484-
"<span title=\"Restricted Visibility\">&nbsp;🔒</span> "
484+
"<span class=\"priv-item\" title=\"Restricted Visibility\">&nbsp;🔒</span> "
485485
}
486486
}
487487
_ if myitem.is_doc_hidden() => {

src/librustdoc/html/static/css/rustdoc.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,6 +2891,11 @@ in src-script.js and main.js
28912891
margin-bottom: 0;
28922892
}
28932893

2894+
.hide-priv dt:has(.priv-item),
2895+
.hide-priv dt:has(.priv-item) + dd {
2896+
display: none;
2897+
}
2898+
28942899
/* End: styles for --scrape-examples feature */
28952900

28962901
/* Begin: styles for themes

src/librustdoc/html/static/js/settings.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@
9090
removeClass(document.documentElement, "word-wrap-source-code");
9191
}
9292
break;
93+
case "show-private-items":
94+
showPrivateItems(value === true);
9395
}
9496
}
9597

@@ -286,6 +288,11 @@
286288
"js_name": "word-wrap-source-code",
287289
"default": false,
288290
},
291+
{
292+
"name": "Show private items",
293+
"js_name": "show-private-items",
294+
"default": false,
295+
},
289296
];
290297

291298
// Then we build the DOM.
@@ -343,6 +350,19 @@
343350
}
344351
}
345352

353+
/**
354+
* @param {boolean} value
355+
*/
356+
function showPrivateItems(value) {
357+
/*document.querySelectorAll("dt:has([title='Restricted Visibility'])").forEach(x => x.hidden = !value);
358+
*/
359+
if (value) {
360+
removeClass(document.documentElement, "hide-priv");
361+
} else {
362+
addClass(document.documentElement, "hide-priv");
363+
}
364+
}
365+
346366
if (!isSettingsPage) {
347367
// We replace the existing "onclick" callback.
348368
// These elements must exist, as (outside of the settings page)

src/librustdoc/html/static/js/storage.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ if (getSettingValue("sans-serif-fonts") === "true") {
333333
if (getSettingValue("word-wrap-source-code") === "true") {
334334
addClass(document.documentElement, "word-wrap-source-code");
335335
}
336+
if (getSettingValue("show-private-items") !== "true") {
337+
addClass(document.documentElement, "hide-priv");
338+
}
336339
function updateSidebarWidth() {
337340
const desktopSidebarWidth = getSettingValue("desktop-sidebar-width");
338341
if (desktopSidebarWidth && desktopSidebarWidth !== "null") {

0 commit comments

Comments
 (0)