| 116 | } |
| 117 | |
| 118 | export function KeyboardSettings() { |
| 119 | const { settings, updateSettings, resetSettings } = useChatStore(); |
| 120 | const keybindings = settings.keybindings; |
| 121 | |
| 122 | // Find conflicts |
| 123 | const bindingValues = Object.values(keybindings); |
| 124 | const conflicts = new Set( |
| 125 | bindingValues.filter((v, i) => bindingValues.indexOf(v) !== i) |
| 126 | ); |
| 127 | |
| 128 | function rebind(id: string, combo: string) { |
| 129 | updateSettings({ keybindings: { ...keybindings, [id]: combo } }); |
| 130 | } |
| 131 | |
| 132 | function resetOne(id: string) { |
| 133 | updateSettings({ |
| 134 | keybindings: { ...keybindings, [id]: DEFAULT_SHORTCUTS[id] }, |
| 135 | }); |
| 136 | } |
| 137 | |
| 138 | return ( |
| 139 | <div> |
| 140 | <SectionHeader title="Keyboard Shortcuts" onReset={() => resetSettings("keybindings")} /> |
| 141 | |
| 142 | <p className="text-xs text-surface-400 mb-4"> |
| 143 | Click a shortcut to rebind it. Press Escape to cancel. |
| 144 | </p> |
| 145 | |
| 146 | <div> |
| 147 | {Object.entries(keybindings).map(([id, binding]) => ( |
| 148 | <ShortcutRow |
| 149 | key={id} |
| 150 | id={id} |
| 151 | binding={binding} |
| 152 | isDefault={binding === DEFAULT_SHORTCUTS[id]} |
| 153 | isConflict={conflicts.has(binding)} |
| 154 | onRebind={(combo) => rebind(id, combo)} |
| 155 | onReset={() => resetOne(id)} |
| 156 | /> |
| 157 | ))} |
| 158 | </div> |
| 159 | </div> |
| 160 | ); |
| 161 | } |