roots: wire the palette's cmd-k shortcut
commit
343c496roots: wire the palette's cmd-k shortcut
The top bar has advertised a kbd hint since the workbench shell landed without a handler behind it. Cmd+K (Ctrl+K elsewhere) now focuses the palette search input and Escape hands focus back; the form stays a plain GET so the shortcut remains enhancement only.
Assisted-by: Claude:claude-fable-5
Reviews
No reviews of this commit yet — record a verdict below.
Start a review
crates/cli/ents-web/src/assets/ents.js
@@ -1,3 +1,28 @@
+/*
+ * The shell's `⌘K` shortcut: focus the top bar's `.palette` search input
+ * (the `kbd` hint every page renders beside it -- `crate::pages`'s
+ * `layout_shell`). Cmd+K on macOS, Ctrl+K elsewhere; Escape hands focus
+ * back. Enhancement only: the form is a plain GET to `/search` with or
+ * without this handler.
+ */
+(function () {
+ "use strict";
+
+ var input = document.querySelector('.palette input[name="q"]');
+ if (!input) {
+ return;
+ }
+ document.addEventListener("keydown", function (event) {
+ if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") {
+ event.preventDefault();
+ input.focus();
+ input.select();
+ } else if (event.key === "Escape" && document.activeElement === input) {
+ input.blur();
+ }
+ });
+})();
+
/*
* Progressive enhancement for `crate::pages::files`'s raw-source blob view
* (`div.blob[data-path][data-rev]`): click a gutter line number to select