feat: Add support for handling chat input keydown events
This commit is contained in:
@@ -14,6 +14,7 @@ import { useTranslation } from "react-i18next"
|
||||
import { KnowledgeSelect } from "../Knowledge/KnowledgeSelect"
|
||||
import { useSpeechRecognition } from "@/hooks/useSpeechRecognition"
|
||||
import { PiGlobe } from "react-icons/pi"
|
||||
import { handleChatInputKeyDown } from "@/utils/key-down"
|
||||
|
||||
type Props = {
|
||||
dropedFile: File | undefined
|
||||
@@ -144,13 +145,16 @@ export const PlaygroundForm = ({ dropedFile }: Props) => {
|
||||
})
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (e.key === "Process" || e.key === "229") return
|
||||
if (import.meta.env.BROWSER !== "firefox") {
|
||||
if (e.key === "Process" || e.key === "229") return
|
||||
}
|
||||
if (
|
||||
!typing &&
|
||||
e.key === "Enter" &&
|
||||
!e.shiftKey &&
|
||||
!isSending &&
|
||||
sendWhenEnter
|
||||
handleChatInputKeyDown({
|
||||
e,
|
||||
sendWhenEnter,
|
||||
typing,
|
||||
isSending
|
||||
})
|
||||
) {
|
||||
e.preventDefault()
|
||||
stopListening()
|
||||
@@ -244,8 +248,16 @@ export const PlaygroundForm = ({ dropedFile }: Props) => {
|
||||
/>
|
||||
<div className="w-full border-x border-t flex flex-col dark:border-gray-600 rounded-t-xl p-2">
|
||||
<textarea
|
||||
onCompositionStart={() => setTyping(true)}
|
||||
onCompositionEnd={() => setTyping(false)}
|
||||
onCompositionStart={() => {
|
||||
if (import.meta.env.BROWSER !== "firefox") {
|
||||
setTyping(true)
|
||||
}
|
||||
}}
|
||||
onCompositionEnd={() => {
|
||||
if (import.meta.env.BROWSER !== "firefox") {
|
||||
setTyping(false)
|
||||
}
|
||||
}}
|
||||
onKeyDown={(e) => handleKeyDown(e)}
|
||||
ref={textareaRef}
|
||||
className="px-2 py-2 w-full resize-none bg-transparent focus-within:outline-none focus:ring-0 focus-visible:ring-0 ring-0 dark:ring-0 border-0 dark:text-gray-100"
|
||||
|
||||
Reference in New Issue
Block a user