fix: handle IME mode in editor (#1371)

* fix: handle IME mode in editor

* chore: update
This commit is contained in:
boojack
2023-03-17 20:47:55 +08:00
committed by GitHub
parent 2ba0dbf50b
commit e526cef754
3 changed files with 26 additions and 5 deletions

View File

@ -52,6 +52,7 @@ const MemoEditor = () => {
isRequesting: false,
});
const [allowSave, setAllowSave] = useState<boolean>(false);
const [isInIME, setIsInIME] = useState(false);
const editorState = editorStore.state;
const prevEditorStateRef = useRef(editorState);
const editorRef = useRef<EditorRefActions>(null);
@ -113,7 +114,7 @@ const MemoEditor = () => {
return;
}
}
if (event.key === "Enter") {
if (event.key === "Enter" && !isInIME) {
const cursorPosition = editorRef.current.getCursorPosition();
const contentBeforeCursor = editorRef.current.getContent().slice(0, cursorPosition);
const rowValue = last(contentBeforeCursor.split("\n"));
@ -394,6 +395,8 @@ const MemoEditor = () => {
onDrop={handleDropEvent}
onFocus={handleEditorFocus}
onBlur={handleEditorBlur}
onCompositionStart={() => setIsInIME(true)}
onCompositionEnd={() => setIsInIME(false)}
>
<Editor ref={editorRef} {...editorConfig} />
<div className="common-tools-wrapper">