nexus/ui/src/hooks/useKeyboardShortcuts.ts
Nexus Dev 9a81f0e22b feat(nexus): extend command palette search + fix shortcut destructure
CommandPalette now consumes CommandPaletteContext (open/setOpen) and
the internal Cmd+K useEffect is gone — the provider owns the global
listener. The search index gains live groups for conversations (via
chatApi.listConversations) and studio workshops (mapped from the
phase 10 WorkshopSlugs), plus stubbed entries for 8 settings section
anchors that will resolve once phase 13 splits InstanceGeneralSettings
into cards. Recipes are stubbed as a disabled placeholder pending
v1.8's recipe API.

useKeyboardShortcuts: adds `onSearch` to the destructure (the phase
6/11 review noted it was referenced at line 25 but never destructured
at lines 12-17) and adds it to the useEffect dependency list.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 13:23:14 +00:00

57 lines
1.5 KiB
TypeScript

import { useEffect } from "react";
import { isKeyboardShortcutTextInputTarget } from "../lib/keyboardShortcuts";
interface ShortcutHandlers {
enabled?: boolean;
onNewIssue?: () => void;
onToggleSidebar?: () => void;
onTogglePanel?: () => void;
onSearch?: () => void;
}
export function useKeyboardShortcuts({
enabled = true,
onNewIssue,
onToggleSidebar,
onTogglePanel,
onSearch,
}: ShortcutHandlers) {
useEffect(() => {
if (!enabled) return;
function handleKeyDown(e: KeyboardEvent) {
// Cmd+K / Ctrl+K → Search (global, works even from inputs)
if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
e.preventDefault();
onSearch?.();
return;
}
// Don't fire shortcuts when typing in inputs
if (isKeyboardShortcutTextInputTarget(e.target)) {
return;
}
// C → New Issue
if (e.key === "c" && !e.metaKey && !e.ctrlKey && !e.altKey) {
e.preventDefault();
onNewIssue?.();
}
// [ → Toggle Sidebar
if (e.key === "[" && !e.metaKey && !e.ctrlKey) {
e.preventDefault();
onToggleSidebar?.();
}
// ] → Toggle Panel
if (e.key === "]" && !e.metaKey && !e.ctrlKey) {
e.preventDefault();
onTogglePanel?.();
}
}
document.addEventListener("keydown", handleKeyDown);
return () => document.removeEventListener("keydown", handleKeyDown);
}, [enabled, onNewIssue, onToggleSidebar, onTogglePanel, onSearch]);
}