@@ -2,8 +2,8 @@ import { useMemo, useState, type KeyboardEvent } from "react";
22import {
33 defaultAppSettings ,
44 type AppCommandId ,
5+ type AppDefaultKeybindings ,
56 type AppKeybindingOverrides ,
6- type AppKeybindings ,
77 type AppShortcut ,
88} from "@bb/domain" ;
99import { Button } from "@bb/shared-ui/button" ;
@@ -21,6 +21,8 @@ import {
2121 canAssignAppShortcut ,
2222 getCommandShortcut ,
2323 getShortcutConflicts ,
24+ isAppCommandAvailableForClient ,
25+ resetCommandShortcutOverride ,
2426 setCommandShortcutOverride ,
2527} from "@/lib/keyboard-shortcut-settings" ;
2628import {
@@ -41,7 +43,7 @@ import {
4143import { AppCommandShortcutPill } from "@/components/commands/AppCommandShortcutHint" ;
4244import { getBbDesktopInfo } from "@/lib/bb-desktop" ;
4345
44- const EMPTY_KEYBINDINGS : AppKeybindings = [ ] ;
46+ const EMPTY_KEYBINDINGS : AppDefaultKeybindings = [ ] ;
4547const EMPTY_OVERRIDES : AppKeybindingOverrides = [ ] ;
4648const SETTINGS_SHORTCUT_PILL_CLASS =
4749 "rounded-none bg-transparent px-0 py-0 text-foreground opacity-100" ;
@@ -160,10 +162,11 @@ function ShortcutRecorder({
160162
161163interface KeyboardCommandRowProps {
162164 command : AppCommandId ;
163- defaults : AppKeybindings ;
165+ defaults : AppDefaultKeybindings ;
164166 disabled : boolean ;
165167 isDesktop : boolean ;
166168 onChange ( command : AppCommandId , shortcut : AppShortcut | null ) : void ;
169+ onReset ( command : AppCommandId ) : void ;
167170 onRecordingChange ( command : AppCommandId | null ) : void ;
168171 overrides : AppKeybindingOverrides ;
169172 recordingCommand : AppCommandId | null ;
@@ -176,6 +179,7 @@ function KeyboardCommandRow({
176179 disabled,
177180 isDesktop,
178181 onChange,
182+ onReset,
179183 onRecordingChange,
180184 overrides,
181185 platform,
@@ -207,10 +211,12 @@ function KeyboardCommandRow({
207211 true ,
208212 platform ,
209213 ) ;
210- const activeDefaultShortcut = isDesktop
211- ? desktopDefaultShortcut
212- : webDefaultShortcut ;
213- const availableOnClient = activeDefaultShortcut !== null ;
214+ const availableOnClient = isAppCommandAvailableForClient (
215+ defaults ,
216+ command ,
217+ isDesktop ,
218+ platform ,
219+ ) ;
214220 const splitDefaults =
215221 webDefaultShortcut !== null &&
216222 desktopDefaultShortcut !== null &&
@@ -309,16 +315,7 @@ function KeyboardCommandRow({
309315 aria-label = { `Reset shortcut for ${ metadata . label } ` }
310316 className = "size-7"
311317 disabled = { disabled || ! availableOnClient || ! customized }
312- onClick = { ( ) => {
313- const defaultShortcut = getCommandShortcut (
314- defaults ,
315- [ ] ,
316- command ,
317- isDesktop ,
318- platform ,
319- ) ;
320- if ( defaultShortcut !== null ) onChange ( command , defaultShortcut ) ;
321- } }
318+ onClick = { ( ) => onReset ( command ) }
322319 size = "icon"
323320 type = "button"
324321 variant = "ghost"
@@ -384,6 +381,16 @@ export function KeyboardSettingsSection() {
384381 } ) ;
385382 }
386383
384+ function resetCommand ( command : AppCommandId ) {
385+ const previous = overrides ;
386+ const next = resetCommandShortcutOverride ( overrides , command ) ;
387+ setDraft ( { sourceKey : serverOverridesKey , value : next } ) ;
388+ updateKeyboardSettings . mutate ( next , {
389+ onError : ( ) =>
390+ setDraft ( { sourceKey : serverOverridesKey , value : previous } ) ,
391+ } ) ;
392+ }
393+
387394 const disabled =
388395 systemConfig . data === undefined || updateKeyboardSettings . isPending ;
389396 const hasOverrides = overrides . length > 0 ;
@@ -451,6 +458,7 @@ export function KeyboardSettingsSection() {
451458 key = { metadata . command }
452459 onChange = { updateCommand }
453460 onRecordingChange = { setRecordingCommand }
461+ onReset = { resetCommand }
454462 overrides = { overrides }
455463 platform = { platform }
456464 recordingCommand = { recordingCommand }
0 commit comments