@@ -7,7 +7,7 @@ import { cn } from "@/app/lib/utils";
77import { getModelById } from "@/server/ai/provider" ;
88import type { AspectRatio } from "@/server/ai/types/api" ;
99import { Image , Send , SlidersHorizontal , X , ZoomIn } from "lucide-react" ;
10- import { type KeyboardEvent , useEffect , useRef , useState } from "react" ;
10+ import { type KeyboardEvent , useCallback , useEffect , useRef , useState } from "react" ;
1111import { useTranslation } from "react-i18next" ;
1212import { ImagePreferences } from "./ImagePreferences" ;
1313
@@ -32,6 +32,7 @@ export function ChatInput({ onSendMessage, disabled, currentProvider, currentMod
3232 const [ showPreferences , setShowPreferences ] = useState ( false ) ;
3333 const fileInputRef = useRef < HTMLInputElement > ( null ) ;
3434 const textareaRef = useRef < HTMLTextAreaElement > ( null ) ;
35+ const isComposingRef = useRef ( false ) ;
3536
3637 // Get current model capability and max images
3738 const { currentModelCapability, maxImages } = ( ( ) => {
@@ -97,12 +98,21 @@ export function ChatInput({ onSendMessage, disabled, currentProvider, currentMod
9798 } ;
9899
99100 const handleKeyDown = ( e : KeyboardEvent < HTMLTextAreaElement > ) => {
100- if ( e . key === "Enter" && ! e . shiftKey ) {
101+ // Ignore Enter key during IME composition (e.g., Chinese input method)
102+ if ( e . key === "Enter" && ! e . shiftKey && ! isComposingRef . current ) {
101103 e . preventDefault ( ) ;
102104 handleSend ( ) ;
103105 }
104106 } ;
105107
108+ const handleCompositionStart = useCallback ( ( ) => {
109+ isComposingRef . current = true ;
110+ } , [ ] ) ;
111+
112+ const handleCompositionEnd = useCallback ( ( ) => {
113+ isComposingRef . current = false ;
114+ } , [ ] ) ;
115+
106116 const handleUploadClick = ( ) => {
107117 fileInputRef . current ?. click ( ) ;
108118 } ;
@@ -237,6 +247,8 @@ export function ChatInput({ onSendMessage, disabled, currentProvider, currentMod
237247 value = { message }
238248 onChange = { ( e ) => setMessage ( e . target . value ) }
239249 onKeyDown = { handleKeyDown }
250+ onCompositionStart = { handleCompositionStart }
251+ onCompositionEnd = { handleCompositionEnd }
240252 placeholder = { t ( "chat.typeMessage" ) }
241253 disabled = { disabled }
242254 className = { cn (
0 commit comments