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 <noreply@anthropic.com>
This commit is contained in:
ccandClaude Opus 5.5 committed 2026-11-19 20:44:27 +01:00
1 parent b014000577
commit e102fd6dc1
8 files changed
+357 -83

No files matched your search

+8
View File
@@ -56,6 +56,14 @@ export default function Files() {
onChange={(e) => setKeyword(e.target.value)}
className="pl-9 pr-9"
/>
{!keyword && (
<kbd
className="pointer-events-none absolute right-2.5 top-1/2 hidden -translate-y-1/2 rounded border bg-muted px-1.5 font-mono text-[11px] text-muted-foreground sm:block"
title="Press / to filter"
>
/
</kbd>
)}
{keyword && (
<Button
variant="ghost"
-20
View File
@@ -219,26 +219,6 @@ export default function FindByKey() {
return () => clearTimeout(timer);
}, [copied]);
// "/" focuses the filter from anywhere on the page.
useEffect(() => {
const onKey = (event: KeyboardEvent) => {
if (event.key !== "/" || event.metaKey || event.ctrlKey || event.altKey)
return;
const target = event.target as HTMLElement | null;
if (
target?.isContentEditable ||
["INPUT", "TEXTAREA", "SELECT"].includes(target?.tagName ?? "")
)
return;
const input = document.getElementById(FILTER_INPUT_ID);
if (!input) return;
event.preventDefault();
(input as HTMLInputElement).select();
};
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, []);
const isFiltering = debouncedKeyword.length > 0;
// Narrowed views (filter, changes only) open every folder; otherwise the
// tree starts with top-level folders open, as before.
-20
View File
@@ -606,26 +606,6 @@ export default function Keys() {
if (y !== null) requestAnimationFrame(() => window.scrollTo(0, y));
}, [loading]);
// "/" focuses the filter from anywhere on the page.
useEffect(() => {
const onKey = (event: KeyboardEvent) => {
if (event.key !== "/" || event.metaKey || event.ctrlKey || event.altKey)
return;
const target = event.target as HTMLElement | null;
if (
target?.isContentEditable ||
["INPUT", "TEXTAREA", "SELECT"].includes(target?.tagName ?? "")
)
return;
const input = document.getElementById(FILTER_INPUT_ID);
if (!input) return;
event.preventDefault();
(input as HTMLInputElement).select();
};
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, []);
const filterControls = (
<div className="relative w-full">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
+1
View File
@@ -55,6 +55,7 @@ export function KeyLink({ entry }: { entry: DisplayedKey }) {
>
<Link
href={href}
data-nav-item
onClick={(event) => {
// Remember exactly where we were, for the find page's back link.
rememberKeysPage({
+258
View File
@@ -0,0 +1,258 @@
"use client";
import { Keyboard } from "lucide-react";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { HEADER_PORTAL_ID } from "@/components/header-portal";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
/**
* Site-wide shortcuts, mounted once in the header:
* / focus the page filter Esc clear it, then leave it
* j / k next / previous item ? this help
* g h|k|f go home / keys / files v version picker
*
* Lists opt in by marking focusable rows with `data-nav-item`. Widgets that
* own their keys (the namespace tree, file trees) handle them first and call
* preventDefault, so they win over these.
*/
/** Marks a focusable row that j/k step through. */
export const NAV_ITEM_ATTR = "data-nav-item";
/** Marks the button that opens the version picker. */
export const VERSION_PICKER_ATTR = "data-version-picker";
const GOTO_WINDOW_MS = 1200;
function isTyping(target: EventTarget | null) {
const el = target as HTMLElement | null;
return Boolean(
el &&
(el.isContentEditable ||
["INPUT", "TEXTAREA", "SELECT"].includes(el.tagName)),
);
}
function headerFilter() {
return document.querySelector<HTMLInputElement>(`#${HEADER_PORTAL_ID} input`);
}
/** Clear a React-controlled input the way typing would. */
function clearInput(input: HTMLInputElement) {
const setter = Object.getOwnPropertyDescriptor(
HTMLInputElement.prototype,
"value",
)?.set;
setter?.call(input, "");
input.dispatchEvent(new Event("input", { bubbles: true }));
}
function visible(el: HTMLElement) {
return el.offsetParent !== null || el.getClientRects().length > 0;
}
/** Move focus to the next/previous `data-nav-item` in the page content. */
function stepItems(direction: 1 | -1) {
const items = [
...document.querySelectorAll<HTMLElement>(`main [${NAV_ITEM_ATTR}]`),
].filter(visible);
if (items.length === 0) return;
const current = items.indexOf(document.activeElement as HTMLElement);
let next: HTMLElement | undefined;
if (current !== -1) {
next = items[current + direction];
} else {
// Nothing focused yet: start from what's on screen.
const onScreen = items.filter((el) => {
const rect = el.getBoundingClientRect();
return rect.bottom > 0 && rect.top < window.innerHeight;
});
next = direction === 1 ? onScreen[0] : onScreen.at(-1);
next ??= items[direction === 1 ? 0 : items.length - 1];
}
if (!next) return;
next.focus();
next.scrollIntoView({ block: "nearest" });
}
export function KeyboardShortcuts({ os }: { os: string }) {
const router = useRouter();
const [helpOpen, setHelpOpen] = useState(false);
useEffect(() => {
let gotoAt = 0;
const onKey = (event: KeyboardEvent) => {
if (
event.defaultPrevented ||
event.metaKey ||
event.ctrlKey ||
event.altKey
)
return;
if (isTyping(event.target)) {
const input = event.target as HTMLInputElement;
if (event.key === "Escape" && input === headerFilter()) {
event.preventDefault();
if (input.value) clearInput(input);
else input.blur();
}
return;
}
// "g" then a letter: go to a page.
if (performance.now() - gotoAt < GOTO_WINDOW_MS) {
gotoAt = 0;
const target =
event.key === "h"
? "/"
: os && event.key === "k"
? `/os/keys?os=${encodeURIComponent(os)}`
: os && event.key === "f"
? `/os/files?os=${encodeURIComponent(os)}`
: null;
if (target) {
event.preventDefault();
router.push(target);
return;
}
}
switch (event.key) {
case "/": {
const input = headerFilter();
if (!input) return;
event.preventDefault();
input.focus();
input.select();
return;
}
case "?":
event.preventDefault();
setHelpOpen(true);
return;
case "j":
case "k":
event.preventDefault();
stepItems(event.key === "j" ? 1 : -1);
return;
case "g":
gotoAt = performance.now();
return;
case "v": {
const picker = document.querySelector<HTMLElement>(
`[${VERSION_PICKER_ATTR}]`,
);
if (!picker) return;
event.preventDefault();
picker.click();
return;
}
}
};
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [os, router]);
return (
<>
<button
type="button"
onClick={() => setHelpOpen(true)}
className="hidden shrink-0 rounded-md p-2 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground sm:block"
title="Keyboard shortcuts (?)"
aria-label="Keyboard shortcuts"
>
<Keyboard className="h-4 w-4" />
</button>
<Dialog open={helpOpen} onOpenChange={setHelpOpen}>
<DialogContent className="sm:max-w-lg">
<DialogHeader>
<DialogTitle>Keyboard shortcuts</DialogTitle>
<DialogDescription>
Available everywhere unless you&apos;re typing in a field.
</DialogDescription>
</DialogHeader>
<div className="grid gap-5 text-sm sm:grid-cols-2">
{SHORTCUTS.map((group) => (
<section key={group.title}>
<h3 className="mb-2 text-xs font-medium uppercase tracking-wide text-muted-foreground">
{group.title}
</h3>
<dl className="space-y-1.5">
{group.items.map(([keys, label]) => (
<div
key={label}
className="flex items-center justify-between gap-3"
>
<dt className="text-muted-foreground">{label}</dt>
<dd className="flex shrink-0 gap-1">
{keys.map((key) => (
<kbd
key={key}
className="min-w-6 rounded border bg-muted px-1.5 py-0.5 text-center font-mono text-xs"
>
{key}
</kbd>
))}
</dd>
</div>
))}
</dl>
</section>
))}
</div>
</DialogContent>
</Dialog>
</>
);
}
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)"],
],
},
];
+30 -10
View File
@@ -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 (
<div className="flex items-center gap-2 sm:gap-4 text-sm min-w-0">
<div className="flex items-center gap-1 sm:gap-2 shrink-0">
<span className="text-muted-foreground hidden sm:inline">{platform}</span>
<span className="text-muted-foreground hidden sm:inline">
{platform}
</span>
<VersionSwitcher currentOs={os} />
</div>
@@ -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 (
<header className="sticky top-0 z-50 shrink-0 border-b border-border bg-background">
@@ -127,12 +138,20 @@ export function NavTop() {
{/* Left group: logo + breadcrumb + left portal */}
<div className="flex items-center gap-4 min-w-0 flex-wrap">
<h1 className="text-xl font-bold shrink-0">
<Link href="/" className="hover:text-muted-foreground transition-colors">
<Link
href="/"
className="hover:text-muted-foreground transition-colors"
>
entdb
</Link>
</h1>
{isHome && <HomeControls />}
{isHome && <div id={HEADER_PORTAL_LEFT_ID} className="hidden sm:flex items-center" />}
{isHome && (
<div
id={HEADER_PORTAL_LEFT_ID}
className="hidden sm:flex items-center"
/>
)}
{isOSPage && os && <OSBreadcrumb os={os} currentPage={currentPage} />}
</div>
@@ -146,7 +165,8 @@ export function NavTop() {
className="flex min-w-0 max-w-xl flex-1 items-center gap-2"
/>
)}
<div className="ml-auto">
<div className="ml-auto flex items-center">
<KeyboardShortcuts os={os} />
<ThemeToggle />
</div>
</div>
+34 -23
View File
@@ -207,6 +207,38 @@ export default function OSList() {
return (
<div>
{/* The filter is usable before the list loads (no header shift). */}
<HeaderPortal>
<div className="relative flex-1 sm:flex-none sm:w-80">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
<Input
type="text"
placeholder="Filter..."
value={keyword}
onChange={(e) => setKeyword(e.target.value)}
className="pl-9 pr-9"
/>
{!keyword && (
<kbd
className="pointer-events-none absolute right-2.5 top-1/2 hidden -translate-y-1/2 rounded border bg-muted px-1.5 font-mono text-[11px] text-muted-foreground sm:block"
title="Press / to filter"
>
/
</kbd>
)}
{keyword && (
<Button
variant="ghost"
size="sm"
onClick={() => setKeyword("")}
className="absolute right-1 top-1/2 -translate-y-1/2 h-7 w-7 p-0"
>
<X className="h-4 w-4" />
</Button>
)}
</div>
</HeaderPortal>
{loading && (
<div aria-busy="true" aria-label="Loading builds">
{SKELETON_SECTIONS.map(({ cards, codenames }, section) => (
@@ -265,29 +297,6 @@ export default function OSList() {
</div>
</HeaderPortal>
<HeaderPortal>
<div className="relative flex-1 sm:flex-none sm:w-80">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
<Input
type="text"
placeholder="Filter..."
value={keyword}
onChange={(e) => setKeyword(e.target.value)}
className="pl-9 pr-9"
/>
{keyword && (
<Button
variant="ghost"
size="sm"
onClick={() => setKeyword("")}
className="absolute right-1 top-1/2 -translate-y-1/2 h-7 w-7 p-0"
>
<X className="h-4 w-4" />
</Button>
)}
</div>
</HeaderPortal>
{/* Mobile platform buttons - shown inline in content */}
<div className="flex sm:hidden items-center gap-1 mb-4">
{groups.map((group) => (
@@ -332,6 +341,7 @@ export default function OSList() {
className="list-none"
>
<Link
data-nav-item
href={`/os/keys?os=${group.name}/${os.version}_${os.build}`}
className={cn(
"block p-3 border rounded-lg transition-colors hover:bg-accent/50",
@@ -372,6 +382,7 @@ export default function OSList() {
className="list-none"
>
<Link
data-nav-item
href={`/os/keys?os=${group.name}/${os.version}_${os.build}`}
className={cn(
"block p-3 border rounded-lg transition-colors hover:bg-accent/50",
+26 -10
View File
@@ -1,19 +1,20 @@
"use client";
import { useEffect, useState } from "react";
import { useRouter, usePathname, useSearchParams } from "next/navigation";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { ChevronDown, Check } from "lucide-react";
import { Check, ChevronDown } from "lucide-react";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { useEffect, useState } from "react";
import type { OS } from "@/lib/types";
import { withBase, basePath, dataURL } from "@/lib/env";
import { BetaBadge } from "@/components/beta-badge";
import { VERSION_PICKER_ATTR } from "@/components/keyboard-shortcuts";
import { basePath, dataURL } from "@/lib/env";
import type { OS } from "@/lib/types";
function compareVersion(a: string, b: string) {
const l1 = a.split(".").map(Number);
@@ -53,11 +54,14 @@ export function VersionSwitcher({ currentOs }: { currentOs: string }) {
}, [group]);
const currentVersion = versions.find(
(v) => 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"
/>
</div>