fix file not exists when reopen project

This commit is contained in:
codetypes committed 2025-04-17 15:41:13 +08:00
1 parent 6894aacfd1
commit e21c32e800
1 file changed
+7 -2
+7 -2
View File
@@ -227,7 +227,8 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
init: (path) => {
const workspace = get();
const files = useSetting.getState().getEditors(path);
const setting = useSetting.getState();
const files = setting.getEditors(path);
if (!workspace.workdir) {
try {
workspace.workdir = Path.dirname(path).replaceAll(Path.sep, "/");
@@ -236,16 +237,20 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
workspace.loadTrees();
workspace.loadNodeDefs();
workspace.watch();
useSetting.getState().appendRecent(path);
setting.appendRecent(path);
if (files.length) {
for (const entry of files) {
try {
if (fs.existsSync(entry.path)) {
entry.path = Path.posixPath(entry.path);
const editor = new EditorStore(entry.path);
workspace.editors.push(editor);
if (entry.active) {
workspace.open(editor.path);
}
} else {
setting.closeEditor(workspace.path, entry.path);
}
} catch (error) {
console.error(error);
message.error(`invalid file: ${path}`);