"use client"; import { useMemo, useState } from "react"; type Shortcut = { id: string; combos: string[][]; description: string; note?: string; }; type ShortcutCategory = { id: string; title: string; blurb?: string; shortcuts: Shortcut[]; }; const CATEGORIES: ShortcutCategory[] = [ { id: "workspaces", title: "Workspaces", blurb: "Workspaces live in the sidebar. Each workspace has its own set of panes and surfaces.", shortcuts: [ { id: "ws-new", combos: [["⌘", "N"]], description: "New workspace" }, { id: "ws-jump-1-8", combos: [["⌘", "1–8"]], description: "Jump to workspace 1–8", }, { id: "ws-jump-last", combos: [["⌘", "9"]], description: "Jump to last workspace", }, { id: "ws-close", combos: [["⌘", "⇧", "W"]], description: "Close workspace", }, { id: "ws-rename", combos: [["⌘", "⇧", "R"]], description: "Rename workspace", }, ], }, { id: "surfaces", title: "Surfaces", blurb: "Surfaces are tabs inside a pane.", shortcuts: [ { id: "sf-new", combos: [["⌘", "T"]], description: "New surface" }, { id: "sf-prev-1", combos: [["⌘", "⇧", "["]], description: "Previous surface", }, { id: "sf-prev-2", combos: [["⌃", "⇧", "Tab"]], description: "Previous surface", }, { id: "sf-jump-1-8", combos: [["⌃", "1–8"]], description: "Jump to surface 1–8", }, { id: "sf-jump-last", combos: [["⌃", "9"]], description: "Jump to last surface", }, { id: "sf-close", combos: [["⌘", "W"]], description: "Close surface" }, ], }, { id: "split-panes", title: "Split Panes", shortcuts: [ { id: "sp-right", combos: [["⌘", "D"]], description: "Split right" }, { id: "sp-down", combos: [["⌘", "⇧", "D"]], description: "Split down" }, { id: "sp-focus", combos: [["⌥", "⌘", "←/→/↑/↓"]], description: "Focus pane directionally", }, { id: "sp-browser-right", combos: [["⌥", "⌘", "D"]], description: "Split browser right", }, { id: "sp-browser-down", combos: [["⌥", "⌘", "⇧", "D"]], description: "Split browser down", }, ], }, { id: "browser", title: "Browser", shortcuts: [ { id: "br-open", combos: [["⌘", "⇧", "L"]], description: "Open browser surface", }, { id: "br-addr", combos: [["⌘", "L"]], description: "Focus address bar" }, { id: "br-forward", combos: [["⌘", "]"]], description: "Forward" }, { id: "br-reload", combos: [["⌘", "R"]], description: "Reload page" }, { id: "br-devtools", combos: [["⌥", "⌘", "I"]], description: "Open Developer Tools", }, ], }, { id: "notifications", title: "Notifications", shortcuts: [ { id: "nt-panel", combos: [["⌘", "⇧", "I"]], description: "Show notifications panel", }, { id: "nt-latest", combos: [["⌘", "⇧", "U"]], description: "Jump to latest unread", }, { id: "nt-flash", combos: [["⌘", "⇧", "L"]], description: "Trigger flash", }, ], }, { id: "find", title: "Find", shortcuts: [ { id: "fd-find", combos: [["⌘", "F"]], description: "Find" }, { id: "fd-next-prev", combos: [ ["⌘", "G"], ["⌘", "⇧", "G"], ], description: "Find next / previous", }, { id: "fd-hide", combos: [["⌘", "⇧", "F"]], description: "Hide find bar", }, { id: "fd-selection", combos: [["⌘", "E"]], description: "Use selection for find", }, ], }, { id: "terminal", title: "Terminal", shortcuts: [ { id: "tm-clear", combos: [["⌘", "K"]], description: "Clear scrollback", }, { id: "tm-copy", combos: [["⌘", "C"]], description: "Copy (with selection)", }, { id: "tm-paste", combos: [["⌘", "V"]], description: "Paste" }, { id: "tm-font", combos: [ ["⌘", "+"], ["⌘", "-"], ], description: "Increase / decrease font size", }, { id: "tm-reset", combos: [["⌘", "0"]], description: "Reset font size" }, ], }, { id: "window", title: "Window", shortcuts: [ { id: "wn-new", combos: [["⌘", "⇧", "N"]], description: "New window" }, { id: "wn-settings", combos: [["⌘", ","]], description: "Settings" }, { id: "wn-reload", combos: [["⌘", "⇧", "R"]], description: "Reload configuration", }, { id: "wn-quit", combos: [["⌘", "Q"]], description: "Quit" }, ], }, ]; function normalize(s: string) { return s.toLowerCase().replace(/\s+/g, " ").trim(); } function comboToText(combo: string[]) { return combo.join(" "); } function shortcutSearchText(category: ShortcutCategory, s: Shortcut) { const combos = s.combos.map(comboToText).join(" "); return normalize(`${category.title} ${combos} ${s.description} ${s.note ?? ""}`); } function KeyCombo({ combo }: { combo: string[] }) { return ( {combo.map((k, idx) => ( {k} {idx < combo.length - 1 && ( + )} ))} ); } function ShortcutRow({ shortcut }: { shortcut: Shortcut }) { return (
{shortcut.description} {shortcut.note && ( {shortcut.note} )}
{shortcut.combos.map((combo, idx) => ( {idx > 0 && ( / )} ))}
); } export function KeyboardShortcuts() { const [query, setQuery] = useState(""); const filtered = useMemo(() => { const q = normalize(query); if (!q) return CATEGORIES; return CATEGORIES.map((cat) => ({ ...cat, shortcuts: cat.shortcuts.filter((s) => shortcutSearchText(cat, s).includes(q), ), })).filter((cat) => cat.shortcuts.length > 0); }, [query]); return (
{/* Search */}
setQuery(e.target.value)} placeholder="Search shortcuts..." className="w-full pl-9 pr-3 py-1.5 rounded-lg border border-border bg-transparent text-[13px] placeholder:text-muted/40 focus:outline-none focus:border-foreground/20 transition-colors" aria-label="Search keyboard shortcuts" />
{/* Category jump links */} {!query && ( )} {/* Content */} {filtered.length === 0 ? (

No shortcuts found

Try a different search term

) : (
{filtered.map((cat) => (
{cat.title}
{cat.blurb && (

{cat.blurb}

)}
{cat.shortcuts.map((s) => ( ))}
))}
)}
); }