Skip to content

Commit

Permalink
fix: ignore "Tab" key down event when is composing in editor(#3026) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaychen1e authored Mar 3, 2024
1 parent 9a8a1d0 commit 3b089ee
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion web/src/components/MemoEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ interface State {
relationList: MemoRelation[];
isUploadingResource: boolean;
isRequesting: boolean;
isComposing: boolean;
}

const MemoEditor = (props: Props) => {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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} />
Expand Down

0 comments on commit 3b089ee

Please sign in to comment.