Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading