@@ -13,6 +13,7 @@ export type Hotkey = {
1313 desc : string ;
1414 hotkeys : string [ ] ;
1515 platformKeys : string [ ] [ ] ;
16+ isEnabled : boolean ;
1617} ;
1718
1819type HotkeyCategoryData = { title : string ; hotkeys : Record < string , Hotkey > } ;
@@ -60,14 +61,15 @@ export const useHotkeyData = (): HotkeysData => {
6061 } ,
6162 } ;
6263
63- const addHotkey = ( category : HotkeyCategory , id : string , keys : string [ ] ) => {
64+ const addHotkey = ( category : HotkeyCategory , id : string , keys : string [ ] , isEnabled : boolean = true ) => {
6465 data [ category ] . hotkeys [ id ] = {
6566 id,
6667 category,
6768 title : t ( `hotkeys.${ category } .${ id } .title` ) ,
6869 desc : t ( `hotkeys.${ category } .${ id } .desc` ) ,
6970 hotkeys : keys ,
7071 platformKeys : formatKeysForPlatform ( keys , isMacOS ) ,
72+ isEnabled,
7173 } ;
7274 } ;
7375
@@ -189,17 +191,28 @@ type UseRegisteredHotkeysArg = {
189191} ;
190192
191193/**
192- * A wrapper around `useHotkeys` that registers the hotkey with the hotkey registry.
193- *
194- * Registered hotkeys will be displayed in the hotkeys modal.
194+ * A wrapper around `useHotkeys` that adds a handler for a registered hotkey.
195195 */
196196export const useRegisteredHotkeys = ( { id, category, callback, options, dependencies } : UseRegisteredHotkeysArg ) => {
197197 const hotkeysData = useHotkeyData ( ) ;
198- const keys = useMemo ( ( ) => {
199- const _keys = hotkeysData [ category ] . hotkeys [ id ] ?. hotkeys ;
200- assert ( _keys !== undefined , `Hotkey ${ category } .${ id } not found` ) ;
201- return _keys ;
198+ const data = useMemo ( ( ) => {
199+ const _data = hotkeysData [ category ] . hotkeys [ id ] ;
200+ assert ( _data !== undefined , `Hotkey ${ category } .${ id } not found` ) ;
201+ return _data ;
202202 } , [ category , hotkeysData , id ] ) ;
203-
204- return useHotkeys ( keys , callback , options , dependencies ) ;
203+ const _options = useMemo ( ( ) => {
204+ // If no options are provided, return the default. This includes if the hotkey is globally disabled.
205+ if ( ! options ) {
206+ return {
207+ enabled : data . isEnabled ,
208+ } satisfies Options ;
209+ }
210+ // Otherwise, return the provided optiosn, but override the enabled state.
211+ return {
212+ ...options ,
213+ enabled : data . isEnabled ? options . enabled : false ,
214+ } satisfies Options ;
215+ } , [ data . isEnabled , options ] ) ;
216+
217+ return useHotkeys ( data . hotkeys , callback , _options , dependencies ) ;
205218} ;
0 commit comments