From 3d7308cea0dde31b4a9178725e99f0eb36d61266 Mon Sep 17 00:00:00 2001 From: Eugene Date: Thu, 18 Jul 2024 23:53:23 +0200 Subject: [PATCH] fixed #9751 - title/color observers not detaching when detaching a tab --- .../src/components/splitTab.component.ts | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tabby-core/src/components/splitTab.component.ts b/tabby-core/src/components/splitTab.component.ts index 94b59675..b187fcb3 100644 --- a/tabby-core/src/components/splitTab.component.ts +++ b/tabby-core/src/components/splitTab.component.ts @@ -1,4 +1,4 @@ -import { Observable, Subject } from 'rxjs' +import { Observable, Subject, takeUntil, takeWhile } from 'rxjs' import { Component, Injectable, ViewChild, ViewContainerRef, EmbeddedViewRef, AfterViewInit, OnDestroy, Injector } from '@angular/core' import { BaseTabComponent, BaseTabProcess, GetRecoveryTokenOptions } from './baseTab.component' import { TabRecoveryProvider, RecoveryToken } from '../api/tabRecovery' @@ -837,20 +837,38 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit }) } - tab.subscribeUntilDestroyed(tab.titleChange$, () => this.updateTitle()) - tab.subscribeUntilDestroyed(tab.activity$, a => a ? this.displayActivity() : this.clearActivity()) - tab.subscribeUntilDestroyed(tab.progress$, p => this.setProgress(p)) + tab.subscribeUntilDestroyed( + this.observeUntilChildDetached(tab.titleChange$), + () => this.updateTitle(), + ) + tab.subscribeUntilDestroyed( + this.observeUntilChildDetached(tab.activity$), + a => a ? this.displayActivity() : this.clearActivity(), + ) + tab.subscribeUntilDestroyed( + this.observeUntilChildDetached(tab.progress$), + p => this.setProgress(p), + ) if (tab.title) { this.updateTitle() } - tab.subscribeUntilDestroyed(tab.recoveryStateChangedHint$, () => { - this.recoveryStateChangedHint.next() - }) + tab.subscribeUntilDestroyed( + this.observeUntilChildDetached(tab.recoveryStateChangedHint$), + () => { + this.recoveryStateChangedHint.next() + }, + ) tab.destroyed$.subscribe(() => { this.removeTab(tab) }) } + private observeUntilChildDetached (tab: BaseTabComponent, event: Observable): Observable { + return event.pipe(takeWhile(() => { + this.getAllTabs().includes(tab) + })) + } + private onAfterTabAdded (tab: BaseTabComponent) { setImmediate(() => { this.layout()