diff --git a/packages/workspace/src/window.ts b/packages/workspace/src/window.ts index 41b9c53ea..0e37b4986 100644 --- a/packages/workspace/src/window.ts +++ b/packages/workspace/src/window.ts @@ -51,9 +51,6 @@ export class EditorWindow implements IEditorWindow { this.title = config.title; this.icon = resource.icon; this.sleep = config.sleep; - if (!config.sleep) { - this.init(); - } } async importSchema(schema: any) { @@ -155,6 +152,8 @@ export class EditorWindow implements IEditorWindow { return; } + this.editorView.setActivate(true); + if (!ignoreEmit) { this.emitter.emit('window.change.view.type', name); @@ -162,7 +161,6 @@ export class EditorWindow implements IEditorWindow { this.workspace.emitChangeActiveEditorView(); } } - this.editorView.setActivate(true); }; get project() { diff --git a/packages/workspace/src/workspace.ts b/packages/workspace/src/workspace.ts index ba3d91c41..46c8c4a0e 100644 --- a/packages/workspace/src/workspace.ts +++ b/packages/workspace/src/workspace.ts @@ -115,7 +115,7 @@ export class Workspace implements IWorkspace { } } - initWindow() { + async initWindow() { if (!this.defaultResourceType || this.enableAutoOpenFirstWindow === false) { return; } @@ -127,6 +127,7 @@ export class Workspace implements IWorkspace { this.window = new EditorWindow(resource, this, { title: resource.title, }); + await this.window.init(); this.editorWindowMap.set(this.window.id, this.window); this.windows = [...this.windows, this.window]; this.emitChangeWindow(); @@ -196,6 +197,9 @@ export class Workspace implements IWorkspace { this.windows.splice(index, 1); if (this.window === window) { this.window = this.windows[index] || this.windows[index + 1] || this.windows[index - 1]; + if (this.window.sleep) { + this.window.init(); + } this.emitChangeActiveWindow(); } this.emitChangeWindow(); @@ -206,10 +210,13 @@ export class Workspace implements IWorkspace { this.remove(index); } - openEditorWindowById(id: string) { + async openEditorWindowById(id: string) { const window = this.editorWindowMap.get(id); if (window) { this.window = window; + if (window.sleep) { + await window.init(); + } this.emitChangeActiveWindow(); } } @@ -252,6 +259,7 @@ export class Workspace implements IWorkspace { this.editorWindowMap.set(window.id, window); if (!sleep) { this.window = window; + await this.window.init(); } this.emitChangeWindow(); this.emitChangeActiveWindow();