From 98b3e37144a4437cb20f339fe092bab742b4de3b Mon Sep 17 00:00:00 2001 From: katsuma <71871253+SuzukiKatsuma@users.noreply.github.com> Date: Thu, 7 Nov 2024 22:21:50 +0900 Subject: [PATCH] fix: simplify Enter key handling and remove unused ref (#10413) --- .../base/chat/chat/chat-input-area/index.tsx | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/web/app/components/base/chat/chat/chat-input-area/index.tsx b/web/app/components/base/chat/chat/chat-input-area/index.tsx index 05aaaa6bc2..32d841148a 100644 --- a/web/app/components/base/chat/chat/chat-input-area/index.tsx +++ b/web/app/components/base/chat/chat/chat-input-area/index.tsx @@ -1,6 +1,5 @@ import { useCallback, - useRef, useState, } from 'react' import Textarea from 'rc-textarea' @@ -63,7 +62,6 @@ const ChatInputArea = ({ isMultipleLine, } = useTextAreaHeight() const [query, setQuery] = useState('') - const isUseInputMethod = useRef(false) const [showVoiceInput, setShowVoiceInput] = useState(false) const filesStore = useFileStore() const { @@ -95,20 +93,11 @@ const ChatInputArea = ({ } } - const handleKeyUp = (e: React.KeyboardEvent) => { - if (e.key === 'Enter') { - e.preventDefault() - // prevent send message when using input method enter - if (!e.shiftKey && !isUseInputMethod.current) - handleSend() - } - } - const handleKeyDown = (e: React.KeyboardEvent) => { - isUseInputMethod.current = e.nativeEvent.isComposing - if (e.key === 'Enter' && !e.shiftKey) { - setQuery(query.replace(/\n$/, '')) + if (e.key === 'Enter' && !e.shiftKey && !e.nativeEvent.isComposing) { e.preventDefault() + setQuery(query.replace(/\n$/, '')) + handleSend() } } @@ -165,7 +154,6 @@ const ChatInputArea = ({ setQuery(e.target.value) handleTextareaResize() }} - onKeyUp={handleKeyUp} onKeyDown={handleKeyDown} onPaste={handleClipboardPasteFile} onDragEnter={handleDragFileEnter}