Skip to content

Commit 67a240c

Browse files
authored
Merge pull request #7 from ewfian/fix/ime-composition
fix: Prevent Enter key from sending message during IME composition
2 parents 1b3a545 + 0964bdc commit 67a240c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/renderer/src/components/pages/chat/ChatInput.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ const ChatInput = React.memo(forwardRef<ChatInputRef, ChatInputProps>(
198198
ref
199199
) => {
200200
const textAreaRef = useRef<any>(null)
201+
const isComposingRef = useRef(false)
201202
const { settings } = useSettingsStore()
202203

203204
const insertQuote = useCallback((text: string) => {
@@ -225,16 +226,24 @@ const ChatInput = React.memo(forwardRef<ChatInputRef, ChatInputProps>(
225226
}))
226227

227228
const handleKeyDown = useCallback((e: React.KeyboardEvent) => {
228-
if (e.key === 'Enter' && !e.shiftKey) {
229+
if (e.key === 'Enter' && !e.shiftKey && !isComposingRef.current) {
229230
e.preventDefault()
230231
onSend()
231232
}
232233
}, [onSend])
233-
234+
234235
const handleTextChange = useCallback((e: React.ChangeEvent<HTMLTextAreaElement>) => {
235236
onChange(e.target.value)
236237
}, [onChange])
237238

239+
const handleCompositionStart = useCallback(() => {
240+
isComposingRef.current = true
241+
}, [])
242+
243+
const handleCompositionEnd = useCallback(() => {
244+
isComposingRef.current = false
245+
}, [])
246+
238247
const hasNoModels = !llmConfigs || llmConfigs.length === 0
239248
const hasNoSelectedModel = !selectedModel
240249

@@ -288,6 +297,8 @@ const ChatInput = React.memo(forwardRef<ChatInputRef, ChatInputProps>(
288297
value={value}
289298
onChange={handleTextChange}
290299
onKeyDown={handleKeyDown}
300+
onCompositionStart={handleCompositionStart}
301+
onCompositionEnd={handleCompositionEnd}
291302
autoSize={{ minRows: 1, maxRows: 10 }}
292303
disabled={hasNoModels}
293304
/>

0 commit comments

Comments
 (0)