From 7bc549b555fcfcc153478eea578c4bfef25c575d Mon Sep 17 00:00:00 2001 From: Eugene Date: Sun, 20 Aug 2023 19:40:28 +0200 Subject: [PATCH] cleanup, delay canvas rescaling --- .../src/components/baseTab.component.ts | 2 ++ .../src/api/baseTerminalTab.component.ts | 36 ++++++++++--------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/tabby-core/src/components/baseTab.component.ts b/tabby-core/src/components/baseTab.component.ts index 94c52b467..773c43398 100644 --- a/tabby-core/src/components/baseTab.component.ts +++ b/tabby-core/src/components/baseTab.component.ts @@ -84,6 +84,7 @@ export abstract class BaseTabComponent extends BaseComponent { get focused$ (): Observable { return this.focused } get blurred$ (): Observable { return this.blurred } + /* @hidden */ get visibility$ (): Observable { return this.visibility } get titleChange$ (): Observable { return this.titleChange.pipe(distinctUntilChanged()) } get progress$ (): Observable { return this.progress.pipe(distinctUntilChanged()) } @@ -179,6 +180,7 @@ export abstract class BaseTabComponent extends BaseComponent { this.blurred.next() } + /* @hidden */ emitVisibility (visibility: boolean): void { this.visibility.next(visibility) } diff --git a/tabby-terminal/src/api/baseTerminalTab.component.ts b/tabby-terminal/src/api/baseTerminalTab.component.ts index e7c35a6cc..d074dff19 100644 --- a/tabby-terminal/src/api/baseTerminalTab.component.ts +++ b/tabby-terminal/src/api/baseTerminalTab.component.ts @@ -1,4 +1,4 @@ -import { Observable, Subject, first, auditTime } from 'rxjs' +import { Observable, Subject, first, auditTime, debounce, interval } from 'rxjs' import { Spinner } from 'cli-spinner' import colors from 'ansi-colors' import { NgZone, OnInit, OnDestroy, Injector, ViewChild, HostBinding, Input, ElementRef, InjectFlags, Component } from '@angular/core' @@ -14,6 +14,9 @@ import { TerminalDecorator } from './decorator' import { SearchPanelComponent } from '../components/searchPanel.component' import { MultifocusService } from '../services/multifocus.service' + +const INACTIVE_TAB_UNLOAD_DELAY = 1000 * 30 + /** * A class to base your custom terminal tabs on */ @@ -409,22 +412,23 @@ export class BaseTerminalTabComponent

extends Bas this.multifocus.cancel() }) - this.visibility$.subscribe(visibility => { - if (this.frontend instanceof XTermFrontend) { - if (visibility) { - // this.frontend.resizeHandler() - const term = this.frontend.xterm as any - term._core._renderService.clear() - term._core._renderService.handleResize(term.cols, term.rows) - } else { - this.frontend.xterm.element?.querySelectorAll('canvas').forEach(c => { - c.height = c.width = 0 - c.style.height = c.style.width = '0px' - }) + this.visibility$ + .pipe(debounce(visibility => interval(visibility ? 0 : INACTIVE_TAB_UNLOAD_DELAY))) + .subscribe(visibility => { + if (this.frontend instanceof XTermFrontend) { + if (visibility) { + // this.frontend.resizeHandler() + const term = this.frontend.xterm as any + term._core._renderService.clear() + term._core._renderService.handleResize(term.cols, term.rows) + } else { + this.frontend.xterm.element?.querySelectorAll('canvas').forEach(c => { + c.height = c.width = 0 + c.style.height = c.style.width = '0px' + }) + } } - } - console.log('visibility:', this.title, visibility) - }) + }) } protected onFrontendReady (): void {