-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcreateKbdShortcuts.ts
More file actions
35 lines (28 loc) · 947 Bytes
/
Copy pathcreateKbdShortcuts.ts
File metadata and controls
35 lines (28 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { onMount, onCleanup } from 'solid-js';
import { tinykeys } from 'tinykeys';
import { useStore } from './StoreContext';
import { createActionList } from './createActionList';
import { getShortcutHandlersMap } from './actionUtils/actionUtils';
type Unsubscribe = null | ReturnType<typeof tinykeys>;
export function createKbdShortcuts() {
const [state, storeMethods] = useStore();
const { togglePalette } = storeMethods;
const actionsList = createActionList();
let unsubscribe: Unsubscribe = null;
onMount(() => {
const shortcutMap = getShortcutHandlersMap(actionsList(), state.actionsContext, storeMethods);
const commandPaletteHandler = (event: KeyboardEvent) => {
event.preventDefault();
togglePalette();
};
unsubscribe = tinykeys(window, {
...shortcutMap,
'$mod+k': commandPaletteHandler,
});
});
onCleanup(() => {
if (unsubscribe) {
unsubscribe();
}
});
}