Skip to content

Commit f819417

Browse files
yz778mrdjohnson
authored andcommitted
feat: ctrl+j to focus chat input box
feat: ctrl+j to focus chat input box
1 parent 1f50368 commit f819417

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/components/ChatBoxInputRow.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ChatViewModel } from '~/core/chat/ChatViewModel'
88
import { connectionStore } from '~/core/connection/ConnectionStore'
99
import { incomingMessageStore } from '~/core/IncomingMessageStore'
1010
import { TransferHandler } from '~/core/TransferHandler'
11+
import { focusStore } from '~/core/FocusStore'
1112

1213
import AttachmentWrapper from '~/components/AttachmentWrapper'
1314
import CachedImage from '~/components/CachedImage'
@@ -106,6 +107,14 @@ const ChatBoxInputRow = ({ chat, onSend, children }: ChatBoxInputRowProps) => {
106107
}
107108
}, [inputDisabled, chat, messageToEdit])
108109

110+
// Handle focus requests from focusStore
111+
useEffect(() => {
112+
if (focusStore.shouldFocusChatInput && textareaRef.current && !inputDisabled) {
113+
textareaRef.current.focus({ preventScroll: true })
114+
focusStore.clearFocusRequest()
115+
}
116+
}, [focusStore.shouldFocusChatInput, inputDisabled])
117+
109118
return (
110119
<div
111120
className={twMerge(

src/components/OmniBar.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { settingStore } from '~/core/setting/SettingStore'
1414
import { personaStore } from '~/core/persona/PersonaStore'
1515
import { chatStore } from '~/core/chat/ChatStore'
1616
import { connectionStore } from '~/core/connection/ConnectionStore'
17+
import { focusStore } from '~/core/FocusStore'
1718

1819
import { messageTable } from '~/core/message/MessageTable'
1920

@@ -554,6 +555,10 @@ const OmniBar = () => {
554555
event.preventDefault()
555556
chatStore.createChat()
556557
},
558+
'$mod+j': (event: Event) => {
559+
event.preventDefault()
560+
focusStore.focusChatInput()
561+
},
557562
})
558563
}, [])
559564

src/core/FocusStore.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { makeAutoObservable } from 'mobx'
2+
3+
class FocusStore {
4+
shouldFocusChatInput = false
5+
6+
constructor() {
7+
makeAutoObservable(this)
8+
}
9+
10+
focusChatInput() {
11+
this.shouldFocusChatInput = true
12+
}
13+
14+
clearFocusRequest() {
15+
this.shouldFocusChatInput = false
16+
}
17+
}
18+
19+
export const focusStore = new FocusStore()

0 commit comments

Comments
 (0)