Skip to content
App Hotkeys API Reference

AppHotkeysStore

Defined in: app-hotkeys.ts:363

Holds declared app hotkeys and the user's custom hotkeys. Framework providers create one and expose it through hooks; devtools read it from HotkeyManager.appHotkeys.

Example

ts
const store = new AppHotkeysStore(appHotkeys, {
  customHotkeys: JSON.parse(localStorage.getItem('hotkeys') ?? '{}'),
  onCustomHotkeysChange: (custom) =>
    localStorage.setItem('hotkeys', JSON.stringify(custom)),
})
store.setCustomHotkey('doc.save', 'Mod+Shift+S')

Type Parameters

T

T extends AppHotkeys = AppHotkeys

Constructors

Constructor

ts
new AppHotkeysStore<T>(appHotkeys, options?): AppHotkeysStore<T>;

Defined in: app-hotkeys.ts:368

Parameters

appHotkeys

T

options?

AppHotkeysStoreOptions<T> = {}

Returns

AppHotkeysStore<T>

Properties

store

ts
readonly store: Store<AppHotkeysState<T>>;

Defined in: app-hotkeys.ts:364

Accessors

appHotkeys

Get Signature

ts
get appHotkeys(): T;

Defined in: app-hotkeys.ts:386

Effective app hotkeys.

Returns

T


customHotkeys

Get Signature

ts
get customHotkeys(): CustomHotkeys<T>;

Defined in: app-hotkeys.ts:391

The user's hotkeys that differ from the defaults.

Returns

CustomHotkeys<T>

Methods

findConflicts()

ts
findConflicts(id, hotkey): AppHotkey<string, 
  | HotkeyChord
  | HotkeySequence
  | null>[];

Defined in: app-hotkeys.ts:428

Other app hotkeys that would collide if id used hotkey. App hotkeys collide when their scopes match or either is 'global', and their hotkeys are equal or one sequence starts with the other.

Parameters

id

keyof T & string

hotkey

Hotkey

Returns

AppHotkey<string, | HotkeyChord | HotkeySequence | null>[]


get()

ts
get(id): 
  | AppHotkey<string, 
  | HotkeyChord
  | HotkeySequence
  | null>
  | undefined;

Defined in: app-hotkeys.ts:418

Effective app hotkey for an id, or undefined when it is not declared.

Parameters

id

string

Returns

| AppHotkey<string, | HotkeyChord | HotkeySequence | null> | undefined


getList()

ts
getList(registrations): AppHotkeyListItem<T[keyof T]>[];

Defined in: app-hotkeys.ts:499

Joins app hotkeys with live registrations, in declaration order. Adapters call this with the manager's registration views.

Parameters

registrations

Iterable<HotkeyRegistrationView>

Returns

AppHotkeyListItem<T[keyof T]>[]


resetCustomHotkey()

ts
resetCustomHotkey(id): void;

Defined in: app-hotkeys.ts:476

Restores the default hotkey for an app hotkey.

Parameters

id

keyof T & string

Returns

void


resetCustomHotkeys()

ts
resetCustomHotkeys(): void;

Defined in: app-hotkeys.ts:483

Restores every default hotkey.

Returns

void


setAppHotkeys()

ts
setAppHotkeys(appHotkeys): void;

Defined in: app-hotkeys.ts:404

Replaces the declarations, for example after hot module replacement. Custom hotkeys for ids that still exist are kept.

Parameters

appHotkeys

T

Returns

void


setCustomHotkey()

ts
setCustomHotkey(id, hotkey): AppHotkey<string, 
  | HotkeyChord
  | HotkeySequence
  | null>[];

Defined in: app-hotkeys.ts:447

Sets the user's hotkey for an app hotkey. null unbinds it. A hotkey equal to the default removes the customization.

Parameters

id

keyof T & string

hotkey

Hotkey | null

Returns

AppHotkey<string, | HotkeyChord | HotkeySequence | null>[]

Conflicting app hotkeys. When any exist, nothing changes.


setOptions()

ts
setOptions(options): void;

Defined in: app-hotkeys.ts:396

Updates callbacks and other options without resetting custom hotkeys.

Parameters

options

Omit<AppHotkeysStoreOptions<T>, "customHotkeys">

Returns

void