diff --git a/src/services/workbench/__tests__/editorService.test.tsx b/src/services/workbench/__tests__/editorService.test.tsx index f4a6d3328..53f824b78 100644 --- a/src/services/workbench/__tests__/editorService.test.tsx +++ b/src/services/workbench/__tests__/editorService.test.tsx @@ -55,6 +55,17 @@ describe('Test EditorService', () => { ).not.toBeUndefined(); }); + test('Listen to the tab opening event', () => { + const editor = new EditorService(); + expectFnCalled((fun) => { + editor.onOpenTab(fun); + // Open in default Group + editor.open(mockTab); + + expect(fun.mock.calls[0][0]).toEqual(mockTab); + }); + }); + test('Get the default editor options', () => { const editor = new EditorService(); expect(editor.getDefaultEditorOptions()).toEqual(BuiltInEditorOptions); diff --git a/src/services/workbench/editorService.ts b/src/services/workbench/editorService.ts index f66727eeb..8d5761cbd 100644 --- a/src/services/workbench/editorService.ts +++ b/src/services/workbench/editorService.ts @@ -94,6 +94,11 @@ export interface IEditorService extends Component { * @param callback */ onUpdateTab(callback: (tab: IEditorTab) => void): void; + /** + * Listen to the tab opening event + * @param callback + */ + onOpenTab(callback: (tab: IEditorTab) => void): void; /** * Listen to the tab move event * @param callback @@ -562,12 +567,18 @@ export class EditorService groups.push(group); } + this.emit(EditorEvent.OpenTab, tab); + this.setState({ current: group, groups: [...groups], }); } + public onOpenTab(callback: (tab: IEditorTab) => void): void { + this.subscribe(EditorEvent.OpenTab, callback); + } + public closeAll(groupId: number) { const { current, groups = [] } = this.state; const groupIndex = this.getGroupIndexById(groupId);