Skip to content

Commit

Permalink
fix: md select error
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanyxh committed May 21, 2024
1 parent a0e6f03 commit 6350cf2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/filehandle/md_editor/component/MDEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { forwardRef, useImperativeHandle, useMemo, useRef } from 'react';
import { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';

import type { FH } from '@/filehandle/utils/fileManager';

Expand Down Expand Up @@ -159,6 +159,7 @@ const MDEditor = forwardRef<IMDEditorExpose, IMDEditorProps>(function MDEditor(p
const editorContainerRef = useRef<HTMLDivElement>(null);
const editorRef = useRef<Editor>();
const mdStringRef = useRef('');
const latestHandleRef = useRef<FH | null>();

uploadInfo = useMDStore().uploadInfo;

Expand All @@ -168,12 +169,18 @@ const MDEditor = forwardRef<IMDEditorExpose, IMDEditorProps>(function MDEditor(p
}
}));

useMemo(() => {
useEffect(() => {
latestHandleRef.current = currentHandle;

currentHandle
?.getFile()
.then((file) => file.text())
.then((markdown) => {
createMDEditor(editorContainerRef.current!, markdown, onUpdate).then((value) => {
if (latestHandleRef.current && latestHandleRef.current !== currentHandle) {
return value.destroy(true);
}

editorRef.current && editorRef.current.destroy(true);

editorRef.current = value;
Expand Down

0 comments on commit 6350cf2

Please sign in to comment.