Skip to content

Commit

Permalink
fix: markdown delete self no reset
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanyxh committed May 17, 2024
1 parent 65e5602 commit 454d1f8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/filehandle/md_editor/component/MDContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ export const MDContent = forwardRef<IMDContentExpose, IMDContentProps>(
setChanged(changed);
};

const handleRemove = (handle: DH | FH) => {
if (currentHandle === handle) {
setChanged(false);
setCurrentHandle(null);
}
};

const handleSave = async (md: string) => {
if (currentHandle) {
try {
Expand All @@ -134,6 +141,7 @@ export const MDContent = forwardRef<IMDContentExpose, IMDContentProps>(
changed={changed}
update={update}
onSelect={handleSelect}
onRemove={handleRemove}
/>
) : null}

Expand Down
4 changes: 3 additions & 1 deletion src/filehandle/md_editor/component/MDSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface ISidebarProps {
changed: boolean;
update(): void;
onSelect(handle: FH): void;
onRemove(handle: DH | FH): void;
}

interface ExtendFileInfo extends FileInfo {
Expand Down Expand Up @@ -343,7 +344,7 @@ const insetFile = (children: ExtendFileInfo[], child: ExtendFileInfo) => {
};

export const Sidebar: React.FC<Readonly<ISidebarProps>> = (props) => {
const { handle, changed, update, onSelect } = props;
const { handle, changed, update, onSelect, onRemove } = props;

const [list, setList] = useState<ExtendFileInfo[]>([]);
const [activeId, setActiveId] = useState('');
Expand Down Expand Up @@ -457,6 +458,7 @@ export const Sidebar: React.FC<Readonly<ISidebarProps>> = (props) => {
await remove(dh, curr.name);
setList(filter(list, curr.id));

onRemove(curr.handle);
update();
} catch (err) {
error((err as Error).message);
Expand Down

0 comments on commit 454d1f8

Please sign in to comment.