From 56b824d379182981eb5afc7deb698c6623e881cd Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 23 Feb 2022 13:40:56 -0800 Subject: [PATCH] Queue a refresh when registering a decoration Part of microsoft/vscode#143798 --- demo/client.ts | 1 - src/browser/services/DecorationService.ts | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/demo/client.ts b/demo/client.ts index a8283461..fc87eb89 100644 --- a/demo/client.ts +++ b/demo/client.ts @@ -530,7 +530,6 @@ function loadTest() { function addDecoration() { const marker = term.addMarker(1); const decoration = term.registerDecoration({ marker }); - term.write(''); decoration.onRender(() => { decoration.element.style.backgroundColor = 'red'; }); diff --git a/src/browser/services/DecorationService.ts b/src/browser/services/DecorationService.ts index 957a5de5..2f8abb6f 100644 --- a/src/browser/services/DecorationService.ts +++ b/src/browser/services/DecorationService.ts @@ -15,6 +15,7 @@ export class DecorationService extends Disposable implements IDecorationService private _container: HTMLElement | undefined; private _screenElement: HTMLElement | undefined; private _renderService: IRenderService | undefined; + private _animationFrame: number | undefined; constructor(@IInstantiationService private readonly _instantiationService: IInstantiationService) { super(); } @@ -35,9 +36,20 @@ export class DecorationService extends Disposable implements IDecorationService const decoration = this._instantiationService.createInstance(Decoration, decorationOptions, this._container); this._decorations.push(decoration); decoration.onDispose(() => this._decorations.splice(this._decorations.indexOf(decoration), 1)); + this._queueRefresh(); return decoration; } + private _queueRefresh(): void { + if (this._animationFrame !== undefined) { + return; + } + this._animationFrame = window.requestAnimationFrame(() => { + this.refresh(); + this._animationFrame = undefined; + }); + } + public refresh(shouldRecreate?: boolean): void { if (!this._renderService) { return;