Skip to content

Commit 0d5264a

Browse files
committed
Auto merge of #65780 - GuillaumeGomez:move-help-popup-generation-code, r=Mark-Simulacrum
Move help popup generation code The first commit is just a small cleanup. The idea behind this PR is to reduce a bit more the generated HTML files by moving the duplicated code into one place instead. r? @kinnison
2 parents b520af6 + 91ef960 commit 0d5264a

File tree

2 files changed

+49
-57
lines changed

2 files changed

+49
-57
lines changed

src/librustdoc/html/layout.rs

-55
Original file line numberDiff line numberDiff line change
@@ -106,61 +106,6 @@ pub fn render<T: Print, S: Print>(
106106
<section id=\"main\" class=\"content\">{content}</section>\
107107
<section id=\"search\" class=\"content hidden\"></section>\
108108
<section class=\"footer\"></section>\
109-
<aside id=\"help\" class=\"hidden\">\
110-
<div>\
111-
<h1 class=\"hidden\">Help</h1>\
112-
<div class=\"shortcuts\">\
113-
<h2>Keyboard Shortcuts</h2>\
114-
<dl>\
115-
<dt><kbd>?</kbd></dt>\
116-
<dd>Show this help dialog</dd>\
117-
<dt><kbd>S</kbd></dt>\
118-
<dd>Focus the search field</dd>\
119-
<dt><kbd>↑</kbd></dt>\
120-
<dd>Move up in search results</dd>\
121-
<dt><kbd>↓</kbd></dt>\
122-
<dd>Move down in search results</dd>\
123-
<dt><kbd>↹</kbd></dt>\
124-
<dd>Switch tab</dd>\
125-
<dt><kbd>&#9166;</kbd></dt>\
126-
<dd>Go to active search result</dd>\
127-
<dt><kbd>+</kbd></dt>\
128-
<dd>Expand all sections</dd>\
129-
<dt><kbd>-</kbd></dt>\
130-
<dd>Collapse all sections</dd>\
131-
</dl>\
132-
</div>\
133-
<div class=\"infos\">\
134-
<h2>Search Tricks</h2>\
135-
<p>\
136-
Prefix searches with a type followed by a colon (e.g., \
137-
<code>fn:</code>) to restrict the search to a given type.\
138-
</p>\
139-
<p>\
140-
Accepted types are: <code>fn</code>, <code>mod</code>, \
141-
<code>struct</code>, <code>enum</code>, \
142-
<code>trait</code>, <code>type</code>, <code>macro</code>, \
143-
and <code>const</code>.\
144-
</p>\
145-
<p>\
146-
Search functions by type signature (e.g., \
147-
<code>vec -> usize</code> or <code>* -> vec</code>)\
148-
</p>\
149-
<p>\
150-
Search multiple things at once by splitting your query with comma (e.g., \
151-
<code>str,u8</code> or <code>String,struct:Vec,test</code>)\
152-
</p>\
153-
<p>\
154-
You can look for items with an exact name by putting double quotes around \
155-
your request: <code>\"string\"</code>\
156-
</p>\
157-
<p>\
158-
Look for items inside another one by searching for a path: \
159-
<code>vec::Vec</code>\
160-
</p>\
161-
</div>\
162-
</div>\
163-
</aside>\
164109
{after_content}\
165110
<script>\
166111
window.rootPath = \"{root_path}\";\

src/librustdoc/html/static/main.js

+49-2
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ function getSearchElement() {
12221222
}
12231223
dst = dst[0];
12241224
if (window.location.pathname === dst.pathname) {
1225-
addClass(document.getElementById("search"), "hidden");
1225+
addClass(getSearchElement(), "hidden");
12261226
removeClass(main, "hidden");
12271227
document.location.href = dst.href;
12281228
}
@@ -2458,7 +2458,7 @@ function getSearchElement() {
24582458
function putBackSearch(search_input) {
24592459
if (search_input.value !== "") {
24602460
addClass(main, "hidden");
2461-
removeClass(document.getElementById("search"), "hidden");
2461+
removeClass(getSearchElement(), "hidden");
24622462
if (browserSupportsHistoryApi()) {
24632463
history.replaceState(search_input.value,
24642464
"",
@@ -2557,6 +2557,53 @@ function getSearchElement() {
25572557
}
25582558

25592559
window.addSearchOptions = addSearchOptions;
2560+
2561+
function buildHelperPopup() {
2562+
var popup = document.createElement("aside");
2563+
addClass(popup, "hidden");
2564+
popup.id = "help";
2565+
2566+
var container = document.createElement("div");
2567+
var shortcuts = [
2568+
["?", "Show this help dialog"],
2569+
["S", "Focus the search field"],
2570+
["↑", "Move up in search results"],
2571+
["↓", "Move down in search results"],
2572+
["↹", "Switch tab"],
2573+
["&#9166;", "Go to active search result"],
2574+
["+", "Expand all sections"],
2575+
["-", "Collapse all sections"],
2576+
].map(x => "<dt><kbd>" + x[0] + "</kbd></dt><dd>" + x[1] + "</dd>").join("");
2577+
var div_shortcuts = document.createElement("div");
2578+
addClass(div_shortcuts, "shortcuts");
2579+
div_shortcuts.innerHTML = "<h2>Keyboard Shortcuts</h2><dl>" + shortcuts + "</dl></div>";
2580+
2581+
var infos = [
2582+
"Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to \
2583+
restrict the search to a given type.",
2584+
"Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, \
2585+
<code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, \
2586+
and <code>const</code>.",
2587+
"Search functions by type signature (e.g., <code>vec -> usize</code> or \
2588+
<code>* -> vec</code>)",
2589+
"Search multiple things at once by splitting your query with comma (e.g., \
2590+
<code>str,u8</code> or <code>String,struct:Vec,test</code>)",
2591+
"You can look for items with an exact name by putting double quotes around \
2592+
your request: <code>\"string\"</code>",
2593+
"Look for items inside another one by searching for a path: <code>vec::Vec</code>",
2594+
].map(x => "<p>" + x + "</p>").join("");
2595+
var div_infos = document.createElement("div");
2596+
addClass(div_infos, "infos");
2597+
div_infos.innerHTML = "<h2>Search Tricks</h2>" + infos;
2598+
2599+
container.appendChild(div_shortcuts);
2600+
container.appendChild(div_infos);
2601+
2602+
popup.appendChild(container);
2603+
insertAfter(popup, getSearchElement());
2604+
}
2605+
2606+
buildHelperPopup();
25602607
}());
25612608

25622609
// Sets the focus on the search bar at the top of the page

0 commit comments

Comments
 (0)