diff --git a/src/filehandle/md_editor/component/MDContent.tsx b/src/filehandle/md_editor/component/MDContent.tsx index 58b7b36..bd93701 100644 --- a/src/filehandle/md_editor/component/MDContent.tsx +++ b/src/filehandle/md_editor/component/MDContent.tsx @@ -114,6 +114,13 @@ export const MDContent = forwardRef( setChanged(changed); }; + const handleRemove = (handle: DH | FH) => { + if (currentHandle === handle) { + setChanged(false); + setCurrentHandle(null); + } + }; + const handleSave = async (md: string) => { if (currentHandle) { try { @@ -134,6 +141,7 @@ export const MDContent = forwardRef( changed={changed} update={update} onSelect={handleSelect} + onRemove={handleRemove} /> ) : null} diff --git a/src/filehandle/md_editor/component/MDSidebar.tsx b/src/filehandle/md_editor/component/MDSidebar.tsx index fa49eba..9e0ecbd 100644 --- a/src/filehandle/md_editor/component/MDSidebar.tsx +++ b/src/filehandle/md_editor/component/MDSidebar.tsx @@ -26,6 +26,7 @@ interface ISidebarProps { changed: boolean; update(): void; onSelect(handle: FH): void; + onRemove(handle: DH | FH): void; } interface ExtendFileInfo extends FileInfo { @@ -343,7 +344,7 @@ const insetFile = (children: ExtendFileInfo[], child: ExtendFileInfo) => { }; export const Sidebar: React.FC> = (props) => { - const { handle, changed, update, onSelect } = props; + const { handle, changed, update, onSelect, onRemove } = props; const [list, setList] = useState([]); const [activeId, setActiveId] = useState(''); @@ -457,6 +458,7 @@ export const Sidebar: React.FC> = (props) => { await remove(dh, curr.name); setList(filter(list, curr.id)); + onRemove(curr.handle); update(); } catch (err) { error((err as Error).message);