From e526cef754ea8242fc7b33ad0679e9c35622dca2 Mon Sep 17 00:00:00 2001 From: boojack Date: Fri, 17 Mar 2023 20:47:55 +0800 Subject: [PATCH] fix: handle IME mode in editor (#1371) * fix: handle IME mode in editor * chore: update --- web/src/components/AskAIDialog.tsx | 22 +++++++++++++++++-- web/src/components/MemoEditor.tsx | 5 ++++- web/src/components/Settings/SystemSection.tsx | 4 ++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/web/src/components/AskAIDialog.tsx b/web/src/components/AskAIDialog.tsx index fc1f17bd..a3adb304 100644 --- a/web/src/components/AskAIDialog.tsx +++ b/web/src/components/AskAIDialog.tsx @@ -20,6 +20,7 @@ const AskAIDialog: React.FC = (props: Props) => { const fetchingState = useLoading(false); const [historyList, setHistoryList] = useState([]); const [isEnabled, setIsEnabled] = useState(true); + const [isInIME, setIsInIME] = useState(false); const [question, setQuestion] = useState(""); useEffect(() => { @@ -38,15 +39,22 @@ const AskAIDialog: React.FC = (props: Props) => { setQuestion(event.currentTarget.value); }; + const handleKeyDown = (event: React.KeyboardEvent) => { + if (event.key === "Enter" && !event.shiftKey && !isInIME) { + event.preventDefault(); + handleSendQuestionButtonClick(); + } + }; + const handleSendQuestionButtonClick = async () => { fetchingState.setLoading(); + setQuestion(""); try { await askQuestion(question); } catch (error: any) { console.error(error); toast.error(error.response.data.error); } - setQuestion(""); fetchingState.setFinish(); }; @@ -80,7 +88,17 @@ const AskAIDialog: React.FC = (props: Props) => {
-