Skip to content

Commit 2148f0f

Browse files
committed
add missing file
1 parent 3fdea2b commit 2148f0f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}

0 commit comments

Comments
 (0)