From ae958c2b120b0e4343b3304570affa0ff663a62d Mon Sep 17 00:00:00 2001 From: meganrogge Date: Tue, 8 Feb 2022 21:41:26 -0600 Subject: [PATCH] fix the problem --- src/browser/Terminal.ts | 2 +- src/browser/services/DecorationService.ts | 14 ++++++++++---- src/browser/services/Services.ts | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/browser/Terminal.ts b/src/browser/Terminal.ts index bd79b7c5..f1c799f2 100644 --- a/src/browser/Terminal.ts +++ b/src/browser/Terminal.ts @@ -578,7 +578,7 @@ export class Terminal extends CoreTerminal implements ITerminal { this.linkifier.attachToDom(this.element, this._mouseZoneManager); this.linkifier2.attachToDom(this.screenElement, this._mouseService, this._renderService); - this.decorationService.attachToDom(this.screenElement); + this.decorationService.attachToDom(this.screenElement, this._renderService, this._bufferService); // This event listener must be registered aftre MouseZoneManager is created this.register(addDisposableDomListener(this.element, 'mousedown', (e: MouseEvent) => this._selectionService!.onMouseDown(e))); diff --git a/src/browser/services/DecorationService.ts b/src/browser/services/DecorationService.ts index cd32743b..2fea87c3 100644 --- a/src/browser/services/DecorationService.ts +++ b/src/browser/services/DecorationService.ts @@ -14,17 +14,20 @@ export class DecorationService extends Disposable implements IDecorationService private readonly _decorations: Decoration[] = []; private _screenElement: HTMLElement | undefined; + private _renderService: IRenderService | undefined; + private _bufferService: IBufferService | undefined; + constructor( - @IBufferService private readonly _bufferService: IBufferService, - @IRenderService private readonly _renderService: IRenderService, @IInstantiationService private readonly _instantiationService: IInstantiationService ) { super(); - this.register(this._renderService.onRenderedBufferChange(() => this.refresh())); } - public attachToDom(screenElement: HTMLElement): void { + public attachToDom(screenElement: HTMLElement, renderService: IRenderService, bufferService: IBufferService): void { this._screenElement = screenElement; + this._renderService = renderService; + this._bufferService = bufferService; + this.register(this._renderService.onRenderedBufferChange(() => this.refresh())); } public registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined { @@ -38,6 +41,9 @@ export class DecorationService extends Disposable implements IDecorationService } public refresh(): void { + if (!this._bufferService || !this._renderService) { + return; + } for (const decoration of this._decorations) { if (!decoration.element) { continue; diff --git a/src/browser/services/Services.ts b/src/browser/services/Services.ts index 5bab6886..7faf3f0f 100644 --- a/src/browser/services/Services.ts +++ b/src/browser/services/Services.ts @@ -10,6 +10,7 @@ import { ISelectionRedrawRequestEvent as ISelectionRequestRedrawEvent, ISelectio import { createDecorator } from 'common/services/ServiceRegistry'; import { IDisposable } from 'common/Types'; import { IDecorationOptions, IDecoration } from 'xterm'; +import { IBufferService } from 'common/services/Services'; export const ICharSizeService = createDecorator('CharSizeService'); export interface ICharSizeService { @@ -120,5 +121,5 @@ export const IDecorationService = createDecorator('Decoratio export interface IDecorationService extends IDisposable { registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined; refresh(): void; - attachToDom(screenElement: HTMLElement): void; + attachToDom(screenElement: HTMLElement, renderService: IRenderService, bufferService: IBufferService): void; }