mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 21:19:00 +08:00
fix: fix the bug where pressing Enter in Chinese input mode on Safari… (#16914)
This commit is contained in:
parent
5d77730c78
commit
094b049c94
@ -80,6 +80,7 @@ const ChatInputArea = ({
|
|||||||
const { checkInputsForm } = useCheckInputsForms()
|
const { checkInputsForm } = useCheckInputsForms()
|
||||||
const historyRef = useRef([''])
|
const historyRef = useRef([''])
|
||||||
const [currentIndex, setCurrentIndex] = useState(-1)
|
const [currentIndex, setCurrentIndex] = useState(-1)
|
||||||
|
const isComposingRef = useRef(false)
|
||||||
const handleSend = () => {
|
const handleSend = () => {
|
||||||
if (isResponding) {
|
if (isResponding) {
|
||||||
notify({ type: 'info', message: t('appDebug.errorMessage.waitForResponse') })
|
notify({ type: 'info', message: t('appDebug.errorMessage.waitForResponse') })
|
||||||
@ -103,8 +104,21 @@ const ChatInputArea = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const handleCompositionStart = () => {
|
||||||
|
// e: React.CompositionEvent<HTMLTextAreaElement>
|
||||||
|
isComposingRef.current = true
|
||||||
|
}
|
||||||
|
const handleCompositionEnd = () => {
|
||||||
|
// safari or some browsers will trigger compositionend before keydown.
|
||||||
|
// delay 50ms for safari.
|
||||||
|
setTimeout(() => {
|
||||||
|
isComposingRef.current = false
|
||||||
|
}, 50)
|
||||||
|
}
|
||||||
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||||
if (e.key === 'Enter' && !e.shiftKey && !e.nativeEvent.isComposing) {
|
if (e.key === 'Enter' && !e.shiftKey && !e.nativeEvent.isComposing) {
|
||||||
|
// if isComposing, exit
|
||||||
|
if (isComposingRef.current) return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
setQuery(query.replace(/\n$/, ''))
|
setQuery(query.replace(/\n$/, ''))
|
||||||
historyRef.current.push(query)
|
historyRef.current.push(query)
|
||||||
@ -188,6 +202,8 @@ const ChatInputArea = ({
|
|||||||
setTimeout(handleTextareaResize, 0)
|
setTimeout(handleTextareaResize, 0)
|
||||||
}}
|
}}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
|
onCompositionStart={handleCompositionStart}
|
||||||
|
onCompositionEnd={handleCompositionEnd}
|
||||||
onPaste={handleClipboardPasteFile}
|
onPaste={handleClipboardPasteFile}
|
||||||
onDragEnter={handleDragFileEnter}
|
onDragEnter={handleDragFileEnter}
|
||||||
onDragLeave={handleDragFileLeave}
|
onDragLeave={handleDragFileLeave}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user