From dd2260a9e0f28b83b8ef88869b89727627b1c310 Mon Sep 17 00:00:00 2001 From: BiggerRain <15911122312@163.COM> Date: Fri, 20 Dec 2024 18:53:41 +0800 Subject: [PATCH] feat: add keyboard events and tooltip (#61) --- .vscode/settings.json | 2 + src-tauri/src/lib.rs | 2 +- .../SearchChat/AutoResizeTextarea.tsx | 26 ++- src/components/SearchChat/ChatSwitch.tsx | 5 +- src/components/SearchChat/InputBox.tsx | 154 +++++++++++++++--- src/components/Settings/GeneralSettings.tsx | 21 ++- src/components/Settings/SettingsPanel.tsx | 2 +- src/components/Settings/index.tsx | 2 +- src/components/UI/Tooltip/index.tsx | 34 ++++ src/components/UI/Tooltip/style.css | 54 ++++++ src/contexts/ThemeContext.tsx | 2 +- src/hooks/useWindows.ts | 1 + src/main.css | 2 +- 13 files changed, 256 insertions(+), 51 deletions(-) create mode 100644 src/components/UI/Tooltip/index.tsx create mode 100644 src/components/UI/Tooltip/style.css diff --git a/.vscode/settings.json b/.vscode/settings.json index d751aff..dd08ab3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,11 +17,13 @@ "maximizable", "Minimizable", "nord", + "nowrap", "nspanel", "nsstring", "partialize", "Raycast", "rehype", + "rgba", "serde", "tailwindcss", "tauri", diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 5cd7dbc..258ead1 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -118,7 +118,7 @@ fn change_shortcut( .on_shortcut(shortcut, move |_app, scut, event| { if scut == &shortcut { if let ShortcutState::Pressed = event.state() { - if main_window.is_focused().unwrap() { + if main_window.is_visible().unwrap() { main_window.hide().unwrap(); } else { main_window.show().unwrap(); diff --git a/src/components/SearchChat/AutoResizeTextarea.tsx b/src/components/SearchChat/AutoResizeTextarea.tsx index 89d50e0..cfd6527 100644 --- a/src/components/SearchChat/AutoResizeTextarea.tsx +++ b/src/components/SearchChat/AutoResizeTextarea.tsx @@ -1,16 +1,15 @@ -import React, { useEffect, useRef } from "react"; +import { useEffect, useRef, useImperativeHandle, forwardRef } from "react"; interface AutoResizeTextareaProps { input: string; setInput: (value: string) => void; - handleKeyDown?: (e: React.KeyboardEvent) => void; } -const AutoResizeTextarea: React.FC = ({ - input, - setInput, - handleKeyDown, -}) => { +// Forward ref to allow parent to interact with this component +const AutoResizeTextarea = forwardRef< + { reset: () => void; focus: () => void }, + AutoResizeTextareaProps +>(({ input, setInput }, ref) => { const textareaRef = useRef(null); useEffect(() => { @@ -21,6 +20,16 @@ const AutoResizeTextarea: React.FC = ({ } }, [input]); + // Expose methods to the parent via ref + useImperativeHandle(ref, () => ({ + reset: () => { + setInput(""); + }, + focus: () => { + textareaRef.current?.focus(); + }, + })); + return (