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
15 changes: 13 additions & 2 deletions src/renderer/src/components/pages/chat/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ const ChatInput = React.memo(forwardRef<ChatInputRef, ChatInputProps>(
ref
) => {
const textAreaRef = useRef<any>(null)
const isComposingRef = useRef(false)
const { settings } = useSettingsStore()

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

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<HTMLTextAreaElement>) => {
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

Expand Down Expand Up @@ -288,6 +297,8 @@ const ChatInput = React.memo(forwardRef<ChatInputRef, ChatInputProps>(
value={value}
onChange={handleTextChange}
onKeyDown={handleKeyDown}
onCompositionStart={handleCompositionStart}
onCompositionEnd={handleCompositionEnd}
autoSize={{ minRows: 1, maxRows: 10 }}
disabled={hasNoModels}
/>
Expand Down