From ac6877aba7c760f9a196e01f9b6b675105497914 Mon Sep 17 00:00:00 2001 From: meganrogge Date: Mon, 7 Feb 2022 10:14:56 -0600 Subject: [PATCH] clean up --- src/browser/services/DecorationsService.ts | 37 ++++++++++------------ 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/browser/services/DecorationsService.ts b/src/browser/services/DecorationsService.ts index a8a10916b..6205f42f7 100644 --- a/src/browser/services/DecorationsService.ts +++ b/src/browser/services/DecorationsService.ts @@ -34,7 +34,6 @@ export class DecorationsService extends Disposable implements IDecorationsServic if (decorationOptions.marker.isDisposed) { return undefined; } - this._resolveDimensions(decorationOptions); const bufferDecoration = new BufferDecoration(decorationOptions, this._screenElement, this._renderService); this._decorations.push(bufferDecoration); return bufferDecoration; @@ -54,27 +53,13 @@ export class DecorationsService extends Disposable implements IDecorationsServic if (line < 0 || line > this._bufferService.rows) { decoration.element.style.display = 'none'; } else { - decoration.element.style.top = `${line *this._renderService.dimensions.scaledCellHeight}px`; + decoration.element.style.top = `${line * this._renderService.dimensions.scaledCellHeight}px`; decoration.element.style.display = 'block'; } } this._animationFrame = undefined; } - private _resolveDimensions(decorationOptions: IBufferDecorationOptions): void { - if (this._renderService.dimensions.scaledCellWidth) { - decorationOptions.width = decorationOptions.width ? decorationOptions.width * this._renderService.dimensions.scaledCellWidth : this._renderService.dimensions.scaledCellWidth; - } else { - throw new Error('unknown cell width'); - } - - if (this._renderService.dimensions.scaledCellHeight) { - decorationOptions.height = decorationOptions.height ? decorationOptions.height * this._renderService.dimensions.scaledCellHeight : this._renderService.dimensions.scaledCellHeight; - } else { - throw new Error('unknown cell height'); - } - } - public dispose(): void { if (this._animationFrame) { window.cancelAnimationFrame(this._animationFrame); @@ -126,12 +111,9 @@ class BufferDecoration extends Disposable implements IDecoration { private _createElement(): void { this._element = document.createElement('div'); this._element.classList.add('xterm-decoration'); + this._resolveDimensions(); this._element.style.width = `${this._decorationOptions.width}px`; this._element.style.height = `${this._decorationOptions.height}px`; - this._element.style.top = `${this._marker.line * this._renderService.dimensions.scaledCellHeight}px`; - if (this._decorationOptions.x && this._decorationOptions.x < 0) { - throw new Error(`Cannot create a decoration with a negative x offset: ${this._decorationOptions.x}`); - } if (this._decorationOptions.anchor === 'right') { this._element.style.right = this._decorationOptions.x ? `${this._decorationOptions.x * this._renderService.dimensions.scaledCellWidth}px` : ''; } else { @@ -139,6 +121,21 @@ class BufferDecoration extends Disposable implements IDecoration { } } + private _resolveDimensions(): void { + if (this._renderService.dimensions.scaledCellWidth) { + this._decorationOptions.width = this._decorationOptions.width ? this._decorationOptions.width * this._renderService.dimensions.scaledCellWidth : this._renderService.dimensions.scaledCellWidth; + } else { + throw new Error('unknown cell width'); + } + + if (this._renderService.dimensions.scaledCellHeight) { + this._decorationOptions.height = this._decorationOptions.height ? this._decorationOptions.height * this._renderService.dimensions.scaledCellHeight : this._renderService.dimensions.scaledCellHeight; + } else { + throw new Error('unknown cell height'); + } + } + + private _render(): void { if (this._screenElement && this._element) { this._screenElement.append(this._element);