diff --git a/terminus-core/src/components/splitTab.component.ts b/terminus-core/src/components/splitTab.component.ts index 9edc3323..d3534d4c 100644 --- a/terminus-core/src/components/splitTab.component.ts +++ b/terminus-core/src/components/splitTab.component.ts @@ -246,6 +246,23 @@ export class SplitTabComponent extends BaseTabComponent { }) } + remove (tab: BaseTabComponent) { + let parent = this.getParent(tab) + let index = parent.children.indexOf(tab) + parent.ratios.splice(index, 1) + parent.children.splice(index, 1) + + let ref = this.viewRefs.get(tab) + this.viewRefs.delete(tab) + this.viewContainer.remove(this.viewContainer.indexOf(ref)) + + this.layout() + + if (this.root.children.length === 0) { + this.destroy() + } + } + addTab (tab: BaseTabComponent) { let ref = this.viewContainer.insert(tab.hostView) as EmbeddedViewRef this.viewRefs.set(tab, ref) @@ -258,6 +275,9 @@ export class SplitTabComponent extends BaseTabComponent { if (tab.title) { this.setTitle(tab.title) } + tab.destroyed$.subscribe(() => { + this.remove(tab) + }) } navigate (dir: SplitDirection) { diff --git a/terminus-core/src/services/app.service.ts b/terminus-core/src/services/app.service.ts index 667eff06..f3be8087 100644 --- a/terminus-core/src/services/app.service.ts +++ b/terminus-core/src/services/app.service.ts @@ -97,6 +97,16 @@ export class AppService { this.hostApp.setTitle(title) } }) + + tab.destroyed$.subscribe(() => { + let newIndex = Math.max(0, this.tabs.indexOf(tab) - 1) + this.tabs = this.tabs.filter((x) => x !== tab) + if (tab === this.activeTab) { + this.selectTab(this.tabs[newIndex]) + } + this.tabsChanged.next() + this.tabClosed.next(tab) + }) } openNewTabRaw (type: TabComponentType, inputs?: any): BaseTabComponent { @@ -177,14 +187,7 @@ export class AppService { if (checkCanClose && !await tab.canClose()) { return } - let newIndex = Math.max(0, this.tabs.indexOf(tab) - 1) - this.tabs = this.tabs.filter((x) => x !== tab) tab.destroy() - if (tab === this.activeTab) { - this.selectTab(this.tabs[newIndex]) - } - this.tabsChanged.next() - this.tabClosed.next(tab) } async duplicateTab (tab: BaseTabComponent) { diff --git a/terminus-terminal/src/components/baseTerminalTab.component.ts b/terminus-terminal/src/components/baseTerminalTab.component.ts index a1b767ce..dc0768d6 100644 --- a/terminus-terminal/src/components/baseTerminalTab.component.ts +++ b/terminus-terminal/src/components/baseTerminalTab.component.ts @@ -370,7 +370,7 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit this.sessionCloseSubscription = this.session.closed$.subscribe(() => { this.frontend.destroy() - this.app.closeTab(this) + this.destroy() }) } }