diff --git a/templates/commands.html b/templates/commands.html
index 8f8bc5c6..c0bb67ca 100644
--- a/templates/commands.html
+++ b/templates/commands.html
@@ -12,7 +12,7 @@
- {% set command_group_description_name = command_group_name | replace(from="_", to="-") %}
+ {% set command_group_description_name = command_group_name | replace(from="_", to="-") %}
+
{{ group_descriptions[command_group_description_name].display }}
{{ group_descriptions[command_group_description_name].description }}
@@ -107,6 +107,55 @@ {{ group_descriptions[command_group_
// Show/hide no results message based on search results
noResultsMessage.style.display = totalVisible === 0 ? "block" : "none";
}
+
+// A URL like /commands/#hash shows only that command group, with its name in
+// the search box. The group key of the filter in effect, or null.
+var activeGroup = null;
+
+function showGroupFromHash() {
+ var key = decodeURIComponent(window.location.hash.slice(1));
+ var groups = document.querySelectorAll(".command-group");
+ var group = Array.prototype.find.call(groups, function (g) {
+ return g.dataset.group === key;
+ });
+ var box = document.getElementById("search-box");
+ if (group) {
+ activeGroup = key;
+ box.value = group.dataset.groupName;
+ groups.forEach(function (g) {
+ g.style.display = g === group ? "" : "none";
+ });
+ group.querySelectorAll(".command-entry").forEach(function (item) {
+ item.style.display = "";
+ });
+ document.getElementById("no-results-message").style.display = "none";
+ document.querySelector(".search-container").scrollIntoView();
+ } else if (!key && activeGroup) {
+ // Back to a URL without a hash.
+ activeGroup = null;
+ box.value = "";
+ searchCommands();
+ }
+}
+
+// Editing the box is a command name search over all groups. Drop the hash so
+// a reload doesn't bring the group back.
+function onSearchInput() {
+ activeGroup = null;
+ if (window.location.hash) {
+ history.replaceState(null, "", window.location.pathname + window.location.search);
+ // replaceState doesn't fire hashchange; the menu listens for it.
+ window.dispatchEvent(new HashChangeEvent("hashchange"));
+ }
+ searchCommands();
+}
+
+showGroupFromHash();
+window.addEventListener("hashchange", showGroupFromHash);
+// The browser scrolls to the group's heading after this runs, hiding the box.
+window.addEventListener("load", function () {
+ if (activeGroup) document.querySelector(".search-container").scrollIntoView();
+});