Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix: prevent Enter submit while IME composing (CJK)
  • Loading branch information
Decayo committed Aug 14, 2025
commit 57776847090ef8c416387201cec74dcfd7fff348
9 changes: 8 additions & 1 deletion src/components/FloatingPromptInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ const FloatingPromptInputInner = (
const [cursorPosition, setCursorPosition] = useState(0);
const [embeddedImages, setEmbeddedImages] = useState<string[]>([]);
const [dragActive, setDragActive] = useState(false);
const [isComposing, setIsComposing] = useState(false);

const textareaRef = useRef<HTMLTextAreaElement>(null);
const expandedTextareaRef = useRef<HTMLTextAreaElement>(null);
Expand Down Expand Up @@ -679,7 +680,9 @@ const FloatingPromptInputInner = (
return;
}

if (e.key === "Enter" && !e.shiftKey && !isExpanded && !showFilePicker && !showSlashCommandPicker) {
// 在中文輸入法組字期間,不要觸發送出(部分瀏覽器 keyCode 會是 229)
const composing = (e as any).nativeEvent?.isComposing || isComposing || (e as any).keyCode === 229;
if (e.key === "Enter" && !e.shiftKey && !isExpanded && !showFilePicker && !showSlashCommandPicker && !composing) {
e.preventDefault();
handleSend();
}
Expand Down Expand Up @@ -834,6 +837,8 @@ const FloatingPromptInputInner = (
ref={expandedTextareaRef}
value={prompt}
onChange={handleTextChange}
onCompositionStart={() => setIsComposing(true)}
onCompositionEnd={() => setIsComposing(false)}
onPaste={handlePaste}
placeholder="Type your message..."
className="min-h-[200px] resize-none"
Expand Down Expand Up @@ -1157,6 +1162,8 @@ const FloatingPromptInputInner = (
value={prompt}
onChange={handleTextChange}
onKeyDown={handleKeyDown}
onCompositionStart={() => setIsComposing(true)}
onCompositionEnd={() => setIsComposing(false)}
onPaste={handlePaste}
placeholder={dragActive ? "Drop images here..." : "Message Claude (@ for files, / for commands)..."}
disabled={disabled}
Expand Down