From 9679f928216247311cd2900add68f0f58262d6e9 Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Tue, 20 Aug 2024 20:22:01 +0530 Subject: [PATCH 1/9] feat: Add support for handling chat input keydown events --- .../Option/Playground/PlaygroundForm.tsx | 28 +++++++++++++------ src/components/Sidepanel/Chat/form.tsx | 24 +++++++++++----- src/utils/key-down.tsx | 19 +++++++++++++ wxt.config.ts | 2 +- 4 files changed, 57 insertions(+), 16 deletions(-) create mode 100644 src/utils/key-down.tsx diff --git a/src/components/Option/Playground/PlaygroundForm.tsx b/src/components/Option/Playground/PlaygroundForm.tsx index 274600e..cb2029a 100644 --- a/src/components/Option/Playground/PlaygroundForm.tsx +++ b/src/components/Option/Playground/PlaygroundForm.tsx @@ -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) => { />