mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-20 12:39:14 +08:00
fix: simplify Enter key handling and remove unused ref (#10413)
This commit is contained in:
parent
6e23903c63
commit
98b3e37144
@ -1,6 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
useCallback,
|
useCallback,
|
||||||
useRef,
|
|
||||||
useState,
|
useState,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import Textarea from 'rc-textarea'
|
import Textarea from 'rc-textarea'
|
||||||
@ -63,7 +62,6 @@ const ChatInputArea = ({
|
|||||||
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 {
|
||||||
@ -95,20 +93,11 @@ const ChatInputArea = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 && !e.nativeEvent.isComposing) {
|
||||||
if (e.key === 'Enter' && !e.shiftKey) {
|
|
||||||
setQuery(query.replace(/\n$/, ''))
|
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
setQuery(query.replace(/\n$/, ''))
|
||||||
|
handleSend()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +154,6 @@ const ChatInputArea = ({
|
|||||||
setQuery(e.target.value)
|
setQuery(e.target.value)
|
||||||
handleTextareaResize()
|
handleTextareaResize()
|
||||||
}}
|
}}
|
||||||
onKeyUp={handleKeyUp}
|
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
onPaste={handleClipboardPasteFile}
|
onPaste={handleClipboardPasteFile}
|
||||||
onDragEnter={handleDragFileEnter}
|
onDragEnter={handleDragFileEnter}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user