| 37 | } |
| 38 | |
| 39 | function ShortcutRow({ |
| 40 | id, |
| 41 | binding, |
| 42 | isDefault, |
| 43 | isConflict, |
| 44 | onRebind, |
| 45 | onReset, |
| 46 | }: { |
| 47 | id: string; |
| 48 | binding: string; |
| 49 | isDefault: boolean; |
| 50 | isConflict: boolean; |
| 51 | onRebind: (combo: string) => void; |
| 52 | onReset: () => void; |
| 53 | }) { |
| 54 | const [listening, setListening] = useState(false); |
| 55 | const ref = useRef<HTMLButtonElement>(null); |
| 56 | const info = SHORTCUT_LABELS[id]; |
| 57 | |
| 58 | useEffect(() => { |
| 59 | if (!listening) return; |
| 60 | function handler(e: KeyboardEvent) { |
| 61 | if (e.key === "Escape") { |
| 62 | setListening(false); |
| 63 | return; |
| 64 | } |
| 65 | const combo = captureKeyCombo(e); |
| 66 | if (combo) { |
| 67 | onRebind(combo); |
| 68 | setListening(false); |
| 69 | } |
| 70 | } |
| 71 | window.addEventListener("keydown", handler); |
| 72 | return () => window.removeEventListener("keydown", handler); |
| 73 | }, [listening, onRebind]); |
| 74 | |
| 75 | return ( |
| 76 | <div |
| 77 | className={cn( |
| 78 | "flex items-center justify-between py-3 border-b border-surface-800 last:border-0", |
| 79 | isConflict && "bg-red-500/5" |
| 80 | )} |
| 81 | > |
| 82 | <div className="flex-1"> |
| 83 | <p className="text-sm text-surface-200">{info?.label ?? id}</p> |
| 84 | <p className="text-xs text-surface-500">{info?.description}</p> |
| 85 | {isConflict && ( |
| 86 | <p className="text-xs text-red-400 mt-0.5">Conflict with another shortcut</p> |
| 87 | )} |
| 88 | </div> |
| 89 | <div className="flex items-center gap-2"> |
| 90 | <button |
| 91 | ref={ref} |
| 92 | onClick={() => setListening(true)} |
| 93 | className={cn( |
| 94 | "px-3 py-1 rounded-md text-xs font-mono transition-colors border", |
| 95 | listening |
| 96 | ? "bg-brand-600/20 border-brand-500 text-brand-300 animate-pulse" |