From 49085bbd5b43c6d14d71dd93c3eba2940d0b1589 Mon Sep 17 00:00:00 2001 From: meganrogge Date: Wed, 2 Feb 2022 20:51:28 -0600 Subject: [PATCH] use decorations service instead of decorations render layer --- src/browser/Terminal.ts | 6 ++- src/browser/renderer/Renderer.ts | 15 ++---- src/browser/renderer/Types.d.ts | 1 - src/browser/renderer/dom/DomRenderer.ts | 1 - .../DecorationsService.ts} | 51 +++++++------------ src/browser/services/RenderService.ts | 4 -- src/browser/services/Services.ts | 1 - 7 files changed, 26 insertions(+), 53 deletions(-) rename src/browser/{renderer/DecorationRenderLayer.ts => services/DecorationsService.ts} (65%) diff --git a/src/browser/Terminal.ts b/src/browser/Terminal.ts index 8026175e..7757e0b7 100644 --- a/src/browser/Terminal.ts +++ b/src/browser/Terminal.ts @@ -55,6 +55,7 @@ import { CoreTerminal } from 'common/CoreTerminal'; import { color, rgba } from 'browser/Color'; import { CharacterJoinerService } from 'browser/services/CharacterJoinerService'; import { toRgbString } from 'common/input/XParseColor'; +import { DecorationsService, IDecorationsService } from 'browser/services/DecorationsService'; // Let it work inside Node.js for automated testing purposes. const document: Document = (typeof window !== 'undefined') ? window.document : null as any; @@ -80,6 +81,7 @@ export class Terminal extends CoreTerminal implements ITerminal { private _charSizeService: ICharSizeService | undefined; private _mouseService: IMouseService | undefined; private _renderService: IRenderService | undefined; + private _decorationsService: IDecorationsService | undefined; private _characterJoinerService: ICharacterJoinerService | undefined; private _selectionService: ISelectionService | undefined; private _soundService: ISoundService | undefined; @@ -513,6 +515,8 @@ export class Terminal extends CoreTerminal implements ITerminal { this.register(this._renderService.onRenderedBufferChange(e => this._onRender.fire(e))); this.onResize(e => this._renderService!.resize(e.cols, e.rows)); + this._decorationsService = this.register(this._instantiationService.createInstance(DecorationsService, this.screenElement)); + this._compositionView = document.createElement('div'); this._compositionView.classList.add('composition-view'); this._compositionHelper = this._instantiationService.createInstance(CompositionHelper, this.textarea, this._compositionView); @@ -999,7 +1003,7 @@ export class Terminal extends CoreTerminal implements ITerminal { } public registerDecoration(decorationOptions: IBufferDecorationOptions): IDecoration | undefined { - return this._renderService?.registerDecoration(decorationOptions); + return this._decorationsService?.registerDecoration(decorationOptions); } /** * Gets whether the terminal has an active selection. diff --git a/src/browser/renderer/Renderer.ts b/src/browser/renderer/Renderer.ts index 3e96fae1..305808a2 100644 --- a/src/browser/renderer/Renderer.ts +++ b/src/browser/renderer/Renderer.ts @@ -10,11 +10,10 @@ import { IRenderLayer, IRenderer, IRenderDimensions, IRequestRedrawEvent } from import { LinkRenderLayer } from 'browser/renderer/LinkRenderLayer'; import { Disposable } from 'common/Lifecycle'; import { IColorSet, ILinkifier, ILinkifier2 } from 'browser/Types'; -import { ICharSizeService, ICoreBrowserService } from 'browser/services/Services'; -import { IBufferService, IOptionsService, ICoreService, IInstantiationService } from 'common/services/Services'; +import { ICharSizeService } from 'browser/services/Services'; +import { IBufferService, IOptionsService, IInstantiationService } from 'common/services/Services'; import { removeTerminalFromCache } from 'browser/renderer/atlas/CharAtlasCache'; import { EventEmitter, IEvent } from 'common/EventEmitter'; -import { DecorationRenderLayer } from 'browser/renderer/DecorationRenderLayer'; import { IBufferDecorationOptions, IDecoration } from 'xterm'; let nextRendererId = 1; @@ -46,8 +45,7 @@ export class Renderer extends Disposable implements IRenderer { instantiationService.createInstance(TextRenderLayer, this._screenElement, 0, this._colors, allowTransparency, this._id), instantiationService.createInstance(SelectionRenderLayer, this._screenElement, 1, this._colors, this._id), instantiationService.createInstance(LinkRenderLayer, this._screenElement, 2, this._colors, this._id, linkifier, linkifier2), - instantiationService.createInstance(CursorRenderLayer, this._screenElement, 3, this._colors, this._id, this._onRequestRedraw), - instantiationService.createInstance(DecorationRenderLayer, this._screenElement, 4, this._colors, this._id, this._onRequestRedraw) + instantiationService.createInstance(CursorRenderLayer, this._screenElement, 3, this._colors, this._id, this._onRequestRedraw) ]; this.dimensions = { scaledCharWidth: 0, @@ -68,13 +66,6 @@ export class Renderer extends Disposable implements IRenderer { this.onOptionsChanged(); } - public registerDecoration(decorationOptions: IBufferDecorationOptions): IDecoration | undefined { - const decorationLayer = this._renderLayers.find(l => l instanceof DecorationRenderLayer); - if (decorationLayer instanceof DecorationRenderLayer) { - return decorationLayer.registerDecoration(decorationOptions); - } - } - public dispose(): void { for (const l of this._renderLayers) { l.dispose(); diff --git a/src/browser/renderer/Types.d.ts b/src/browser/renderer/Types.d.ts index 97e43b61..c5387173 100644 --- a/src/browser/renderer/Types.d.ts +++ b/src/browser/renderer/Types.d.ts @@ -54,7 +54,6 @@ export interface IRenderer extends IDisposable { clear(): void; renderRows(start: number, end: number): void; clearTextureAtlas?(): void; - registerDecoration(decorationOptions: IBufferDecorationOptions): IDecoration | undefined; } export interface IRenderLayer extends IDisposable { diff --git a/src/browser/renderer/dom/DomRenderer.ts b/src/browser/renderer/dom/DomRenderer.ts index ba23e573..2057c791 100644 --- a/src/browser/renderer/dom/DomRenderer.ts +++ b/src/browser/renderer/dom/DomRenderer.ts @@ -13,7 +13,6 @@ import { IOptionsService, IBufferService, IInstantiationService } from 'common/s import { EventEmitter, IEvent } from 'common/EventEmitter'; import { color } from 'browser/Color'; import { removeElementFromParent } from 'browser/Dom'; -import { DecorationRenderLayer } from 'browser/renderer/DecorationRenderLayer'; import { IBufferDecorationOptions, IDecoration } from 'xterm'; const TERMINAL_CLASS_PREFIX = 'xterm-dom-renderer-owner-'; diff --git a/src/browser/renderer/DecorationRenderLayer.ts b/src/browser/services/DecorationsService.ts similarity index 65% rename from src/browser/renderer/DecorationRenderLayer.ts rename to src/browser/services/DecorationsService.ts index e1476d16..d168e39b 100644 --- a/src/browser/renderer/DecorationRenderLayer.ts +++ b/src/browser/services/DecorationsService.ts @@ -3,50 +3,35 @@ * @license MIT */ -import { BaseRenderLayer } from 'browser/renderer/BaseRenderLayer'; -import { IRequestRedrawEvent } from 'browser/renderer/Types'; -import { IColorSet } from 'browser/Types'; -import { EventEmitter, IEventEmitter } from 'common/EventEmitter'; +import { IRenderDimensions } from 'browser/renderer/Types'; +import { EventEmitter, IEvent } from 'common/EventEmitter'; import { Disposable } from 'common/Lifecycle'; -import { IBufferService, IOptionsService } from 'common/services/Services'; -import { IBufferDecorationOptions, IDecoration, IEvent, IMarker } from 'xterm'; +import { createDecorator } from 'common/services/ServiceRegistry'; +import { IDisposable } from 'common/Types'; +import { IBufferDecorationOptions, IDecoration, IMarker } from 'xterm'; + +export interface IDecorationsService extends IDisposable { + registerDecoration(decorationOptions: IBufferDecorationOptions): IDecoration | undefined; +} const enum DefaultButton { COLOR = '#5DA5D5' } -export class DecorationRenderLayer extends BaseRenderLayer { - private _decorations: IDecoration[] = []; - constructor( - container: HTMLElement, - zIndex: number, - colors: IColorSet, - rendererId: number, - private _onRequestRedraw: IEventEmitter, - @IBufferService bufferService: IBufferService, - @IOptionsService optionsService: IOptionsService - ) { - super(container, 'decoration', zIndex, true, colors, rendererId, bufferService, optionsService); - // this.registerDecoration({ startMarker: new Marker(1), shape: 'button' }); + +export class DecorationsService extends Disposable implements IDecorationsService { + constructor(private readonly _screenElement: HTMLElement) { + super(); } - - public onGridChanged(startRow: number, endRow: number): void { - for (const decoration of this._decorations) { - (decoration as BufferDecoration).render(); - } - } - - public reset(): void { - - } - public registerDecoration(decorationOptions: IBufferDecorationOptions): IDecoration | undefined { if (decorationOptions.marker.isDisposed) { return undefined; } - return new BufferDecoration(decorationOptions, this._ctx.canvas); + return new BufferDecoration(decorationOptions, this._screenElement); } } + +export const IDecorationsService = createDecorator('DecorationsService'); class BufferDecoration extends Disposable implements IDecoration { private static _nextId = 1; private _marker: IMarker; @@ -86,8 +71,8 @@ class BufferDecoration extends Disposable implements IDecoration { } else { this._element.style.right = decorationOptions.x ? `${decorationOptions.x}px` : '5px'; } - if (this._container.parentElement && this._element) { - this._container.parentElement.append(this._element); + if (this._container && this._element) { + this._container.append(this._element); } } diff --git a/src/browser/services/RenderService.ts b/src/browser/services/RenderService.ts index e2f6300b..d236135a 100644 --- a/src/browser/services/RenderService.ts +++ b/src/browser/services/RenderService.ts @@ -86,10 +86,6 @@ export class RenderService extends Disposable implements IRenderService { } } - public registerDecoration(decorationOptions: IBufferDecorationOptions): IDecoration | undefined { - return this._renderer.registerDecoration(decorationOptions); - } - private _onIntersectionChange(entry: IntersectionObserverEntry): void { this._isPaused = entry.isIntersecting === undefined ? (entry.intersectionRatio === 0) : !entry.isIntersecting; diff --git a/src/browser/services/Services.ts b/src/browser/services/Services.ts index 40cb08d2..8b7a0a77 100644 --- a/src/browser/services/Services.ts +++ b/src/browser/services/Services.ts @@ -52,7 +52,6 @@ export interface IRenderService extends IDisposable { onRefreshRequest: IEvent<{ start: number, end: number }>; dimensions: IRenderDimensions; - registerDecoration(decorationOptions: IBufferDecorationOptions): IDecoration | undefined; refreshRows(start: number, end: number): void; clearTextureAtlas(): void; resize(cols: number, rows: number): void;