handle split pane being closed

This commit is contained in:
Eugene Pankov
2019-03-04 21:26:28 +01:00
parent bcc4a262e2
commit d25751abe7
3 changed files with 31 additions and 8 deletions

View File

@@ -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) { addTab (tab: BaseTabComponent) {
let ref = this.viewContainer.insert(tab.hostView) as EmbeddedViewRef<any> let ref = this.viewContainer.insert(tab.hostView) as EmbeddedViewRef<any>
this.viewRefs.set(tab, ref) this.viewRefs.set(tab, ref)
@@ -258,6 +275,9 @@ export class SplitTabComponent extends BaseTabComponent {
if (tab.title) { if (tab.title) {
this.setTitle(tab.title) this.setTitle(tab.title)
} }
tab.destroyed$.subscribe(() => {
this.remove(tab)
})
} }
navigate (dir: SplitDirection) { navigate (dir: SplitDirection) {

View File

@@ -97,6 +97,16 @@ export class AppService {
this.hostApp.setTitle(title) 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 { openNewTabRaw (type: TabComponentType, inputs?: any): BaseTabComponent {
@@ -177,14 +187,7 @@ export class AppService {
if (checkCanClose && !await tab.canClose()) { if (checkCanClose && !await tab.canClose()) {
return return
} }
let newIndex = Math.max(0, this.tabs.indexOf(tab) - 1)
this.tabs = this.tabs.filter((x) => x !== tab)
tab.destroy() tab.destroy()
if (tab === this.activeTab) {
this.selectTab(this.tabs[newIndex])
}
this.tabsChanged.next()
this.tabClosed.next(tab)
} }
async duplicateTab (tab: BaseTabComponent) { async duplicateTab (tab: BaseTabComponent) {

View File

@@ -370,7 +370,7 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
this.sessionCloseSubscription = this.session.closed$.subscribe(() => { this.sessionCloseSubscription = this.session.closed$.subscribe(() => {
this.frontend.destroy() this.frontend.destroy()
this.app.closeTab(this) this.destroy()
}) })
} }
} }