From 0964bdca1535190f0b0ec54a2f4523d0844030fe Mon Sep 17 00:00:00 2001 From: ewfian Date: Wed, 8 Oct 2025 14:42:14 +0800 Subject: [PATCH] fix: Prevent Enter key from sending message during IME composition - Add compositionStart/End event handlers to track IME state - Only trigger send on Enter when not composing - Fixes issue where Chinese/Japanese input confirmation sends message prematurely --- .../src/components/pages/chat/ChatInput.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/components/pages/chat/ChatInput.tsx b/src/renderer/src/components/pages/chat/ChatInput.tsx index c88fedd..8e37953 100644 --- a/src/renderer/src/components/pages/chat/ChatInput.tsx +++ b/src/renderer/src/components/pages/chat/ChatInput.tsx @@ -198,6 +198,7 @@ const ChatInput = React.memo(forwardRef( ref ) => { const textAreaRef = useRef(null) + const isComposingRef = useRef(false) const { settings } = useSettingsStore() const insertQuote = useCallback((text: string) => { @@ -225,16 +226,24 @@ const ChatInput = React.memo(forwardRef( })) const handleKeyDown = useCallback((e: React.KeyboardEvent) => { - if (e.key === 'Enter' && !e.shiftKey) { + if (e.key === 'Enter' && !e.shiftKey && !isComposingRef.current) { e.preventDefault() onSend() } }, [onSend]) - + const handleTextChange = useCallback((e: React.ChangeEvent) => { onChange(e.target.value) }, [onChange]) + const handleCompositionStart = useCallback(() => { + isComposingRef.current = true + }, []) + + const handleCompositionEnd = useCallback(() => { + isComposingRef.current = false + }, []) + const hasNoModels = !llmConfigs || llmConfigs.length === 0 const hasNoSelectedModel = !selectedModel @@ -288,6 +297,8 @@ const ChatInput = React.memo(forwardRef( value={value} onChange={handleTextChange} onKeyDown={handleKeyDown} + onCompositionStart={handleCompositionStart} + onCompositionEnd={handleCompositionEnd} autoSize={{ minRows: 1, maxRows: 10 }} disabled={hasNoModels} />