Skip to content
Merged
Changes from all commits
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
16 changes: 14 additions & 2 deletions src/app/routes/chat/-components/chat/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { cn } from "@/app/lib/utils";
import { getModelById } from "@/server/ai/provider";
import type { AspectRatio } from "@/server/ai/types/api";
import { Image, Send, SlidersHorizontal, X, ZoomIn } from "lucide-react";
import { type KeyboardEvent, useEffect, useRef, useState } from "react";
import { type KeyboardEvent, useCallback, useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { ImagePreferences } from "./ImagePreferences";

Expand All @@ -32,6 +32,7 @@ export function ChatInput({ onSendMessage, disabled, currentProvider, currentMod
const [showPreferences, setShowPreferences] = useState(false);
const fileInputRef = useRef<HTMLInputElement>(null);
const textareaRef = useRef<HTMLTextAreaElement>(null);
const isComposingRef = useRef(false);

// Get current model capability and max images
const { currentModelCapability, maxImages } = (() => {
Expand Down Expand Up @@ -97,12 +98,21 @@ export function ChatInput({ onSendMessage, disabled, currentProvider, currentMod
};

const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === "Enter" && !e.shiftKey) {
// Ignore Enter key during IME composition (e.g., Chinese input method)
if (e.key === "Enter" && !e.shiftKey && !isComposingRef.current) {
e.preventDefault();
handleSend();
}
};

const handleCompositionStart = useCallback(() => {
isComposingRef.current = true;
}, []);

const handleCompositionEnd = useCallback(() => {
isComposingRef.current = false;
}, []);

const handleUploadClick = () => {
fileInputRef.current?.click();
};
Expand Down Expand Up @@ -237,6 +247,8 @@ export function ChatInput({ onSendMessage, disabled, currentProvider, currentMod
value={message}
onChange={(e) => setMessage(e.target.value)}
onKeyDown={handleKeyDown}
onCompositionStart={handleCompositionStart}
onCompositionEnd={handleCompositionEnd}
placeholder={t("chat.typeMessage")}
disabled={disabled}
className={cn(
Expand Down