mirror of
https://github.com/usememos/memos.git
synced 2024-12-20 09:41:58 +03:00
fix: handle IME mode in editor (#1371)
* fix: handle IME mode in editor * chore: update
This commit is contained in:
parent
2ba0dbf50b
commit
e526cef754
@ -20,6 +20,7 @@ const AskAIDialog: React.FC<Props> = (props: Props) => {
|
|||||||
const fetchingState = useLoading(false);
|
const fetchingState = useLoading(false);
|
||||||
const [historyList, setHistoryList] = useState<History[]>([]);
|
const [historyList, setHistoryList] = useState<History[]>([]);
|
||||||
const [isEnabled, setIsEnabled] = useState<boolean>(true);
|
const [isEnabled, setIsEnabled] = useState<boolean>(true);
|
||||||
|
const [isInIME, setIsInIME] = useState(false);
|
||||||
const [question, setQuestion] = useState<string>("");
|
const [question, setQuestion] = useState<string>("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -38,15 +39,22 @@ const AskAIDialog: React.FC<Props> = (props: Props) => {
|
|||||||
setQuestion(event.currentTarget.value);
|
setQuestion(event.currentTarget.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleKeyDown = (event: React.KeyboardEvent) => {
|
||||||
|
if (event.key === "Enter" && !event.shiftKey && !isInIME) {
|
||||||
|
event.preventDefault();
|
||||||
|
handleSendQuestionButtonClick();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleSendQuestionButtonClick = async () => {
|
const handleSendQuestionButtonClick = async () => {
|
||||||
fetchingState.setLoading();
|
fetchingState.setLoading();
|
||||||
|
setQuestion("");
|
||||||
try {
|
try {
|
||||||
await askQuestion(question);
|
await askQuestion(question);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
toast.error(error.response.data.error);
|
toast.error(error.response.data.error);
|
||||||
}
|
}
|
||||||
setQuestion("");
|
|
||||||
fetchingState.setFinish();
|
fetchingState.setFinish();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -80,7 +88,17 @@ const AskAIDialog: React.FC<Props> = (props: Props) => {
|
|||||||
</div>
|
</div>
|
||||||
<div className="dialog-content-container !w-112 max-w-full">
|
<div className="dialog-content-container !w-112 max-w-full">
|
||||||
<div className="w-full relative">
|
<div className="w-full relative">
|
||||||
<Textarea className="w-full" placeholder="Ask anything…" value={question} onChange={handleQuestionTextareaChange} />
|
<Textarea
|
||||||
|
className="w-full"
|
||||||
|
placeholder="Ask anything…"
|
||||||
|
value={question}
|
||||||
|
minRows={1}
|
||||||
|
maxRows={5}
|
||||||
|
onChange={handleQuestionTextareaChange}
|
||||||
|
onCompositionStart={() => setIsInIME(true)}
|
||||||
|
onCompositionEnd={() => setIsInIME(false)}
|
||||||
|
onKeyDown={handleKeyDown}
|
||||||
|
/>
|
||||||
<Icon.Send
|
<Icon.Send
|
||||||
className="cursor-pointer w-7 p-1 h-auto rounded-md bg-gray-100 dark:bg-zinc-800 absolute right-2 bottom-1.5 shadow hover:opacity-80"
|
className="cursor-pointer w-7 p-1 h-auto rounded-md bg-gray-100 dark:bg-zinc-800 absolute right-2 bottom-1.5 shadow hover:opacity-80"
|
||||||
onClick={handleSendQuestionButtonClick}
|
onClick={handleSendQuestionButtonClick}
|
||||||
|
@ -52,6 +52,7 @@ const MemoEditor = () => {
|
|||||||
isRequesting: false,
|
isRequesting: false,
|
||||||
});
|
});
|
||||||
const [allowSave, setAllowSave] = useState<boolean>(false);
|
const [allowSave, setAllowSave] = useState<boolean>(false);
|
||||||
|
const [isInIME, setIsInIME] = useState(false);
|
||||||
const editorState = editorStore.state;
|
const editorState = editorStore.state;
|
||||||
const prevEditorStateRef = useRef(editorState);
|
const prevEditorStateRef = useRef(editorState);
|
||||||
const editorRef = useRef<EditorRefActions>(null);
|
const editorRef = useRef<EditorRefActions>(null);
|
||||||
@ -113,7 +114,7 @@ const MemoEditor = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.key === "Enter") {
|
if (event.key === "Enter" && !isInIME) {
|
||||||
const cursorPosition = editorRef.current.getCursorPosition();
|
const cursorPosition = editorRef.current.getCursorPosition();
|
||||||
const contentBeforeCursor = editorRef.current.getContent().slice(0, cursorPosition);
|
const contentBeforeCursor = editorRef.current.getContent().slice(0, cursorPosition);
|
||||||
const rowValue = last(contentBeforeCursor.split("\n"));
|
const rowValue = last(contentBeforeCursor.split("\n"));
|
||||||
@ -394,6 +395,8 @@ const MemoEditor = () => {
|
|||||||
onDrop={handleDropEvent}
|
onDrop={handleDropEvent}
|
||||||
onFocus={handleEditorFocus}
|
onFocus={handleEditorFocus}
|
||||||
onBlur={handleEditorBlur}
|
onBlur={handleEditorBlur}
|
||||||
|
onCompositionStart={() => setIsInIME(true)}
|
||||||
|
onCompositionEnd={() => setIsInIME(false)}
|
||||||
>
|
>
|
||||||
<Editor ref={editorRef} {...editorConfig} />
|
<Editor ref={editorRef} {...editorConfig} />
|
||||||
<div className="common-tools-wrapper">
|
<div className="common-tools-wrapper">
|
||||||
|
@ -204,7 +204,7 @@ const SystemSection = () => {
|
|||||||
fontFamily: "monospace",
|
fontFamily: "monospace",
|
||||||
fontSize: "14px",
|
fontSize: "14px",
|
||||||
}}
|
}}
|
||||||
placeholder="Write only"
|
placeholder="OpenAI API Key"
|
||||||
value={openAIConfig.key}
|
value={openAIConfig.key}
|
||||||
onChange={(event) => handleOpenAIConfigKeyChanged(event.target.value)}
|
onChange={(event) => handleOpenAIConfigKeyChanged(event.target.value)}
|
||||||
/>
|
/>
|
||||||
@ -217,7 +217,7 @@ const SystemSection = () => {
|
|||||||
fontFamily: "monospace",
|
fontFamily: "monospace",
|
||||||
fontSize: "14px",
|
fontSize: "14px",
|
||||||
}}
|
}}
|
||||||
placeholder="OpenAI Host. Default: https://api.openai.com"
|
placeholder="OpenAI API Host. Default: https://api.openai.com"
|
||||||
value={openAIConfig.host}
|
value={openAIConfig.host}
|
||||||
onChange={(event) => handleOpenAIConfigHostChanged(event.target.value)}
|
onChange={(event) => handleOpenAIConfigHostChanged(event.target.value)}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user