From e102fd6dc1fa3240e1fde37502cc2bca865fd16f Mon Sep 17 00:00:00 2001 From: cc Date: Thu, 19 Nov 2026 20:44:27 +0100 Subject: [PATCH] feat: site-wide keyboard shortcuts One handler in the header, with a ? help dialog (also a header button): - /: focus the page filter; Esc: clear it, then leave it - j / k: next / previous item in lists (home cards, key list) - g h / g k / g f: go to home / keys / files - v: open the version picker with its search focused; Enter picks the first match Replaces the per-page / handlers; the home filter now renders before the list loads so the header no longer shifts. Co-Authored-By: Claude Opus 5.5 --- src/app/os/files/page.tsx | 8 + src/app/os/find/page.tsx | 20 -- src/app/os/keys/page.tsx | 20 -- src/components/key-link.tsx | 1 + src/components/keyboard-shortcuts.tsx | 258 ++++++++++++++++++++++++++ src/components/navtop.tsx | 40 +++- src/components/oslist.tsx | 57 +++--- src/components/version-switcher.tsx | 36 +++- 8 files changed, 357 insertions(+), 83 deletions(-) create mode 100644 src/components/keyboard-shortcuts.tsx diff --git a/src/app/os/files/page.tsx b/src/app/os/files/page.tsx index 7b282cd..75651a3 100644 --- a/src/app/os/files/page.tsx +++ b/src/app/os/files/page.tsx @@ -56,6 +56,14 @@ export default function Files() { onChange={(e) => setKeyword(e.target.value)} className="pl-9 pr-9" /> + {!keyword && ( + + / + + )} {keyword && ( + + + + Keyboard shortcuts + + Available everywhere unless you're typing in a field. + + +
+ {SHORTCUTS.map((group) => ( +
+

+ {group.title} +

+
+ {group.items.map(([keys, label]) => ( +
+
{label}
+
+ {keys.map((key) => ( + + {key} + + ))} +
+
+ ))} +
+
+ ))} +
+
+
+ + ); +} + +const SHORTCUTS: { title: string; items: [string[], string][] }[] = [ + { + title: "Anywhere", + items: [ + [["/"], "Filter"], + [["Esc"], "Clear / leave filter"], + [["v"], "Switch version"], + [["?"], "Show shortcuts"], + ], + }, + { + title: "Go to", + items: [ + [["g", "h"], "Home"], + [["g", "k"], "Keys"], + [["g", "f"], "Files"], + ], + }, + { + title: "Lists", + items: [ + [["j"], "Next item"], + [["k"], "Previous item"], + [["Enter"], "Open"], + [["⌘", "C"], "Copy focused key"], + ], + }, + { + title: "Trees", + items: [ + [["↑", "↓"], "Move"], + [["→"], "Expand / go in"], + [["←"], "Collapse / go up"], + [["a–z"], "Jump to name (keys)"], + ], + }, +]; diff --git a/src/components/navtop.tsx b/src/components/navtop.tsx index 9ae5ad7..2f58d64 100644 --- a/src/components/navtop.tsx +++ b/src/components/navtop.tsx @@ -1,12 +1,13 @@ "use client"; -import Link from "next/link"; +import { Folder, Key, Moon, Sun } from "lucide-react"; import { useTheme } from "next-themes"; -import { Moon, Sun, Key, Folder } from "lucide-react"; -import { useEffect, useState } from "react"; +import Link from "next/link"; import { usePathname, useSearchParams } from "next/navigation"; -import { VersionSwitcher } from "./version-switcher"; +import { useEffect, useState } from "react"; import { HEADER_PORTAL_ID, HEADER_PORTAL_LEFT_ID } from "./header-portal"; +import { KeyboardShortcuts } from "./keyboard-shortcuts"; +import { VersionSwitcher } from "./version-switcher"; function ThemeToggle() { const { theme, setTheme } = useTheme(); @@ -35,13 +36,18 @@ function ThemeToggle() { ); } -function OSBreadcrumb({ os, currentPage }: { os: string; currentPage: string }) { +function OSBreadcrumb({ + os, + currentPage, +}: { os: string; currentPage: string }) { const [platform] = os.split("/"); return (
- {platform} + + {platform} +
@@ -119,7 +125,12 @@ export function NavTop() { ? "find" : "keys"; - const showHeaderControls = isHome || (isOSPage && (currentPage === "keys" || currentPage === "files" || currentPage === "find")); + const showHeaderControls = + isHome || + (isOSPage && + (currentPage === "keys" || + currentPage === "files" || + currentPage === "find")); return (
@@ -127,12 +138,20 @@ export function NavTop() { {/* Left group: logo + breadcrumb + left portal */}

- + entdb

{isHome && } - {isHome &&
} + {isHome && ( +
+ )} {isOSPage && os && }
@@ -146,7 +165,8 @@ export function NavTop() { className="flex min-w-0 max-w-xl flex-1 items-center gap-2" /> )} -
+
+
diff --git a/src/components/oslist.tsx b/src/components/oslist.tsx index 0937aef..609acbf 100644 --- a/src/components/oslist.tsx +++ b/src/components/oslist.tsx @@ -207,6 +207,38 @@ export default function OSList() { return (
+ {/* The filter is usable before the list loads (no header shift). */} + +
+ + setKeyword(e.target.value)} + className="pl-9 pr-9" + /> + {!keyword && ( + + / + + )} + {keyword && ( + + )} +
+
+ {loading && (
{SKELETON_SECTIONS.map(({ cards, codenames }, section) => ( @@ -265,29 +297,6 @@ export default function OSList() {
- -
- - setKeyword(e.target.value)} - className="pl-9 pr-9" - /> - {keyword && ( - - )} -
-
- {/* Mobile platform buttons - shown inline in content */}
{groups.map((group) => ( @@ -332,6 +341,7 @@ export default function OSList() { className="list-none" > v.build === currentBuild || `${v.version}_${v.build}` === currentBuild + (v) => + v.build === currentBuild || `${v.version}_${v.build}` === currentBuild, ); const filteredVersions = versions.filter((v) => - `${v.version} ${v.build} ${v.name}`.toLowerCase().includes(filter.toLowerCase()) + `${v.version} ${v.build} ${v.name}` + .toLowerCase() + .includes(filter.toLowerCase()), ); const handleSelect = (os: OS) => { @@ -66,7 +70,9 @@ export function VersionSwitcher({ currentOs }: { currentOs: string }) { newParams.set("os", `${group}/${newTag}`); // Strip basePath from pathname since router.push adds it automatically - const pathWithoutBase = pathname.startsWith(basePath) ? pathname.slice(basePath.length) : pathname; + const pathWithoutBase = pathname.startsWith(basePath) + ? pathname.slice(basePath.length) + : pathname; router.push(`${pathWithoutBase}?${newParams.toString()}`); setOpen(false); setFilter(""); @@ -79,6 +85,8 @@ export function VersionSwitcher({ currentOs }: { currentOs: string }) { variant="outline" role="combobox" aria-expanded={open} + {...{ [VERSION_PICKER_ATTR]: "" }} + title="Switch version (v)" className="justify-between min-w-[200px] font-mono" > {loading ? ( @@ -103,6 +111,14 @@ export function VersionSwitcher({ currentOs }: { currentOs: string }) { placeholder="Filter versions..." value={filter} onChange={(e) => setFilter(e.target.value)} + autoFocus + onKeyDown={(e) => { + // Enter picks the first match, so "v 26.1 Enter" switches. + if (e.key === "Enter" && filteredVersions[0]) { + e.preventDefault(); + handleSelect(filteredVersions[0]); + } + }} className="h-8" />