mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-13 00:49:05 +08:00
parent
90d6ebc879
commit
538a5df9d5
@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
useCallback,
|
useCallback,
|
||||||
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import Textarea from 'rc-textarea'
|
import Textarea from 'rc-textarea'
|
||||||
@ -73,7 +74,8 @@ const ChatInputArea = ({
|
|||||||
isDragActive,
|
isDragActive,
|
||||||
} = useFile(visionConfig!)
|
} = useFile(visionConfig!)
|
||||||
const { checkInputsForm } = useCheckInputsForms()
|
const { checkInputsForm } = useCheckInputsForms()
|
||||||
|
const historyRef = useRef([''])
|
||||||
|
const [currentIndex, setCurrentIndex] = useState(-1)
|
||||||
const handleSend = () => {
|
const handleSend = () => {
|
||||||
if (onSend) {
|
if (onSend) {
|
||||||
const { files, setFiles } = filesStore.getState()
|
const { files, setFiles } = filesStore.getState()
|
||||||
@ -92,13 +94,33 @@ const ChatInputArea = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
setQuery(query.replace(/\n$/, ''))
|
setQuery(query.replace(/\n$/, ''))
|
||||||
|
historyRef.current.push(query)
|
||||||
|
setCurrentIndex(historyRef.current.length)
|
||||||
handleSend()
|
handleSend()
|
||||||
}
|
}
|
||||||
|
else if (e.key === 'ArrowUp' && !e.shiftKey && !e.nativeEvent.isComposing) {
|
||||||
|
// When the up key is pressed, output the previous element
|
||||||
|
if (currentIndex > 0) {
|
||||||
|
setCurrentIndex(currentIndex - 1)
|
||||||
|
setQuery(historyRef.current[currentIndex - 1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (e.key === 'ArrowDown' && !e.shiftKey && !e.nativeEvent.isComposing) {
|
||||||
|
// When the down key is pressed, output the next element
|
||||||
|
if (currentIndex < historyRef.current.length - 1) {
|
||||||
|
setCurrentIndex(currentIndex + 1)
|
||||||
|
setQuery(historyRef.current[currentIndex + 1])
|
||||||
|
}
|
||||||
|
else if (currentIndex === historyRef.current.length - 1) {
|
||||||
|
// If it is the last element, clear the input box
|
||||||
|
setCurrentIndex(historyRef.current.length)
|
||||||
|
setQuery('')
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleShowVoiceInput = useCallback(() => {
|
const handleShowVoiceInput = useCallback(() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user