Unverified Commit 3b089eea authored by jjaychen's avatar jjaychen Committed by GitHub

fix: ignore "Tab" key down event when is composing in editor(#3026) (#3027)

parent 9a8a1d01
......@@ -45,6 +45,7 @@ interface State {
relationList: MemoRelation[];
isUploadingResource: boolean;
isRequesting: boolean;
isComposing: boolean;
}
const MemoEditor = (props: Props) => {
......@@ -65,6 +66,7 @@ const MemoEditor = (props: Props) => {
relationList: props.relationList ?? [],
isUploadingResource: false,
isRequesting: false,
isComposing: false,
});
const [hasContent, setHasContent] = useState<boolean>(false);
const editorRef = useRef<EditorRefActions>(null);
......@@ -117,6 +119,20 @@ const MemoEditor = (props: Props) => {
}
}, [memoId]);
const handleCompositionStart = () => {
setState((prevState) => ({
...prevState,
isComposing: true,
}));
};
const handleCompositionEnd = () => {
setState((prevState) => ({
...prevState,
isComposing: false,
}));
};
const handleKeyDown = (event: React.KeyboardEvent) => {
if (!editorRef.current) {
return;
......@@ -131,7 +147,7 @@ const MemoEditor = (props: Props) => {
handleEditorKeydownWithMarkdownShortcuts(event, editorRef.current);
}
if (event.key === "Tab") {
if (event.key === "Tab" && !state.isComposing) {
event.preventDefault();
const tabSpace = " ".repeat(TAB_SPACE_WIDTH);
const cursorPosition = editorRef.current.getCursorPosition();
......@@ -382,6 +398,8 @@ const MemoEditor = (props: Props) => {
onKeyDown={handleKeyDown}
onDrop={handleDropEvent}
onFocus={handleEditorFocus}
onCompositionStart={handleCompositionStart}
onCompositionEnd={handleCompositionEnd}
>
<Editor ref={editorRef} {...editorConfig} />
<ResourceListView resourceList={state.resourceList} setResourceList={handleSetResourceList} />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment