File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
src/client/components/ChatV2 Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { useEffect } from 'react'
2
+
3
+ const isMacOS = ( ) => {
4
+ const userAgent = navigator . userAgent . toLowerCase ( )
5
+ return userAgent . indexOf ( 'mac' ) !== - 1
6
+ }
7
+
8
+ export const KeyCombinations = {
9
+ // @todo key combinations for non-macOS
10
+ RESET_CHAT : isMacOS ( )
11
+ ? {
12
+ key : 'w' ,
13
+ ctrlKey : true ,
14
+ hint : '(ctrl + W)' ,
15
+ }
16
+ : undefined ,
17
+ OPEN_MODEL_SELECTOR : isMacOS ( )
18
+ ? {
19
+ key : 'm' ,
20
+ ctrlKey : true ,
21
+ hint : '(ctrl + M)' ,
22
+ }
23
+ : undefined ,
24
+ }
25
+
26
+ export const useKeyboardCommands = ( { resetChat, openModelSelector } : { resetChat : ( ) => void ; openModelSelector : ( ) => void } ) => {
27
+ useEffect ( ( ) => {
28
+ const handleKeyDown = ( event : KeyboardEvent ) => {
29
+ const resetChatKey = KeyCombinations . RESET_CHAT
30
+ const openModelSelectorKey = KeyCombinations . OPEN_MODEL_SELECTOR
31
+
32
+ if ( resetChatKey && event . key === resetChatKey . key && event . ctrlKey === resetChatKey . ctrlKey ) {
33
+ resetChat ( )
34
+ }
35
+
36
+ if ( openModelSelectorKey && event . key === openModelSelectorKey . key && event . ctrlKey === openModelSelectorKey . ctrlKey ) {
37
+ openModelSelector ( )
38
+ }
39
+ }
40
+
41
+ window . addEventListener ( 'keydown' , handleKeyDown )
42
+
43
+ return ( ) => {
44
+ window . removeEventListener ( 'keydown' , handleKeyDown )
45
+ }
46
+ } , [ resetChat , openModelSelector ] )
47
+ }
You can’t perform that action at this time.
0 commit comments