mirror of
https://github.com/usememos/memos.git
synced 2025-03-29 17:10:37 +01:00
This commit is contained in:
parent
9a8a1d017e
commit
3b089eeae3
@ -45,6 +45,7 @@ interface State {
|
|||||||
relationList: MemoRelation[];
|
relationList: MemoRelation[];
|
||||||
isUploadingResource: boolean;
|
isUploadingResource: boolean;
|
||||||
isRequesting: boolean;
|
isRequesting: boolean;
|
||||||
|
isComposing: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MemoEditor = (props: Props) => {
|
const MemoEditor = (props: Props) => {
|
||||||
@ -65,6 +66,7 @@ const MemoEditor = (props: Props) => {
|
|||||||
relationList: props.relationList ?? [],
|
relationList: props.relationList ?? [],
|
||||||
isUploadingResource: false,
|
isUploadingResource: false,
|
||||||
isRequesting: false,
|
isRequesting: false,
|
||||||
|
isComposing: false,
|
||||||
});
|
});
|
||||||
const [hasContent, setHasContent] = useState<boolean>(false);
|
const [hasContent, setHasContent] = useState<boolean>(false);
|
||||||
const editorRef = useRef<EditorRefActions>(null);
|
const editorRef = useRef<EditorRefActions>(null);
|
||||||
@ -117,6 +119,20 @@ const MemoEditor = (props: Props) => {
|
|||||||
}
|
}
|
||||||
}, [memoId]);
|
}, [memoId]);
|
||||||
|
|
||||||
|
const handleCompositionStart = () => {
|
||||||
|
setState((prevState) => ({
|
||||||
|
...prevState,
|
||||||
|
isComposing: true,
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCompositionEnd = () => {
|
||||||
|
setState((prevState) => ({
|
||||||
|
...prevState,
|
||||||
|
isComposing: false,
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
const handleKeyDown = (event: React.KeyboardEvent) => {
|
const handleKeyDown = (event: React.KeyboardEvent) => {
|
||||||
if (!editorRef.current) {
|
if (!editorRef.current) {
|
||||||
return;
|
return;
|
||||||
@ -131,7 +147,7 @@ const MemoEditor = (props: Props) => {
|
|||||||
|
|
||||||
handleEditorKeydownWithMarkdownShortcuts(event, editorRef.current);
|
handleEditorKeydownWithMarkdownShortcuts(event, editorRef.current);
|
||||||
}
|
}
|
||||||
if (event.key === "Tab") {
|
if (event.key === "Tab" && !state.isComposing) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const tabSpace = " ".repeat(TAB_SPACE_WIDTH);
|
const tabSpace = " ".repeat(TAB_SPACE_WIDTH);
|
||||||
const cursorPosition = editorRef.current.getCursorPosition();
|
const cursorPosition = editorRef.current.getCursorPosition();
|
||||||
@ -382,6 +398,8 @@ const MemoEditor = (props: Props) => {
|
|||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
onDrop={handleDropEvent}
|
onDrop={handleDropEvent}
|
||||||
onFocus={handleEditorFocus}
|
onFocus={handleEditorFocus}
|
||||||
|
onCompositionStart={handleCompositionStart}
|
||||||
|
onCompositionEnd={handleCompositionEnd}
|
||||||
>
|
>
|
||||||
<Editor ref={editorRef} {...editorConfig} />
|
<Editor ref={editorRef} {...editorConfig} />
|
||||||
<ResourceListView resourceList={state.resourceList} setResourceList={handleSetResourceList} />
|
<ResourceListView resourceList={state.resourceList} setResourceList={handleSetResourceList} />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user