From f163f8b4ca99ac6203022b2b8da141db5b1a4a54 Mon Sep 17 00:00:00 2001 From: Madelyn Olson Date: Tue, 17 Nov 2026 05:23:47 +0000 Subject: [PATCH] Filter the command reference to a category when its menu link is clicked Opening /commands/# (a category link in the docs menu) puts the group's name in the search box and shows only that group. Editing the box is the usual command name search over all groups and drops the hash. Signed-off-by: Madelyn Olson --- templates/commands.html | 55 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) 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 @@

Command Reference

- +
@@ -61,8 +61,8 @@

We couldn't find any results matching your search

guarantees the iteration order of a group_by map, so sort the keys. #} {% for command_group_name in grouped | keys | sort %} {% set command_group = grouped[command_group_name] %} -
- {% 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(); +});