| import { | import { | ||||
| useCallback, | useCallback, | ||||
| useRef, | |||||
| useState, | useState, | ||||
| } from 'react' | } from 'react' | ||||
| import Textarea from 'rc-textarea' | import Textarea from 'rc-textarea' | ||||
| isMultipleLine, | isMultipleLine, | ||||
| } = useTextAreaHeight() | } = useTextAreaHeight() | ||||
| const [query, setQuery] = useState('') | const [query, setQuery] = useState('') | ||||
| const isUseInputMethod = useRef(false) | |||||
| const [showVoiceInput, setShowVoiceInput] = useState(false) | const [showVoiceInput, setShowVoiceInput] = useState(false) | ||||
| const filesStore = useFileStore() | const filesStore = useFileStore() | ||||
| const { | const { | ||||
| } | } | ||||
| } | } | ||||
| const handleKeyUp = (e: React.KeyboardEvent<HTMLTextAreaElement>) => { | |||||
| 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<HTMLTextAreaElement>) => { | const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => { | ||||
| 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() | e.preventDefault() | ||||
| setQuery(query.replace(/\n$/, '')) | |||||
| handleSend() | |||||
| } | } | ||||
| } | } | ||||
| setQuery(e.target.value) | setQuery(e.target.value) | ||||
| handleTextareaResize() | handleTextareaResize() | ||||
| }} | }} | ||||
| onKeyUp={handleKeyUp} | |||||
| onKeyDown={handleKeyDown} | onKeyDown={handleKeyDown} | ||||
| onPaste={handleClipboardPasteFile} | onPaste={handleClipboardPasteFile} | ||||
| onDragEnter={handleDragFileEnter} | onDragEnter={handleDragFileEnter} |