From b226eb2d6497304d86396d8dba97f206a2ef7d1c Mon Sep 17 00:00:00 2001 From: meganrogge Date: Mon, 7 Feb 2022 14:49:11 -0600 Subject: [PATCH] throw for negative x --- src/browser/services/DecorationsService.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/browser/services/DecorationsService.ts b/src/browser/services/DecorationsService.ts index 6205f42f..6bac2fea 100644 --- a/src/browser/services/DecorationsService.ts +++ b/src/browser/services/DecorationsService.ts @@ -7,7 +7,7 @@ import { IRenderService } from 'browser/services/Services'; import { EventEmitter, IEvent } from 'common/EventEmitter'; import { Disposable } from 'common/Lifecycle'; import { createDecorator } from 'common/services/ServiceRegistry'; -import { IBufferService } from 'common/services/Services'; +import { IBufferService, ILogService } from 'common/services/Services'; import { IDisposable } from 'common/Types'; import { IBufferDecorationOptions, IDecoration, IMarker } from 'xterm'; @@ -28,6 +28,7 @@ export class DecorationsService extends Disposable implements IDecorationsServic @IRenderService private readonly _renderService: IRenderService ) { super(); + this._renderService.onRefreshRequest(() => this._refresh()); } public registerDecoration(decorationOptions: IBufferDecorationOptions): IDecoration | undefined { @@ -43,7 +44,6 @@ export class DecorationsService extends Disposable implements IDecorationsServic if (this._animationFrame) { return; } - this._animationFrame = window.requestAnimationFrame(() => this._refresh()); } @@ -114,6 +114,11 @@ class BufferDecoration extends Disposable implements IDecoration { this._resolveDimensions(); this._element.style.width = `${this._decorationOptions.width}px`; this._element.style.height = `${this._decorationOptions.height}px`; + + if (this._decorationOptions.x && this._decorationOptions.x < 0) { + throw new Error(`Decoration options x value cannot be negative, but was ${this._decorationOptions.x}`); + } + if (this._decorationOptions.anchor === 'right') { this._element.style.right = this._decorationOptions.x ? `${this._decorationOptions.x * this._renderService.dimensions.scaledCellWidth}px` : ''; } else {