From 8ccbef850eeab0f94c829e71596835e4ab1f5da6 Mon Sep 17 00:00:00 2001 From: meganrogge Date: Tue, 15 Mar 2022 17:38:15 -0400 Subject: [PATCH] only update canvas dimensions when needed --- .../Decorations/BufferDecorationRenderer.ts | 1 - .../Decorations/OverviewRulerRenderer.ts | 27 +++++++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/browser/Decorations/BufferDecorationRenderer.ts b/src/browser/Decorations/BufferDecorationRenderer.ts index 7cc2ee83..116c09a5 100644 --- a/src/browser/Decorations/BufferDecorationRenderer.ts +++ b/src/browser/Decorations/BufferDecorationRenderer.ts @@ -109,6 +109,5 @@ export class BufferDecorationRenderer extends Disposable { private _removeDecoration(decoration: IInternalDecoration): void { this._decorationElements.get(decoration)?.remove(); this._decorationElements.delete(decoration); - decoration.dispose(); } } diff --git a/src/browser/Decorations/OverviewRulerRenderer.ts b/src/browser/Decorations/OverviewRulerRenderer.ts index a797a746..d6d450c3 100644 --- a/src/browser/Decorations/OverviewRulerRenderer.ts +++ b/src/browser/Decorations/OverviewRulerRenderer.ts @@ -35,16 +35,13 @@ export class OverviewRulerRenderer extends Disposable { } else { this._ctx = ctx; } - this._canvas.style.width = `${this._width}px`; - this._canvas.style.height = `${this._screenElement.clientHeight}px`; - this._canvas.width = Math.floor((this._width)* window.devicePixelRatio); - this._canvas.height = Math.floor(this._screenElement.clientHeight * window.devicePixelRatio); + this._queueRefresh(true); this.register(this._bufferService.buffers.onBufferActivate(() => { this._canvas!.style.display = this._bufferService.buffer === this._bufferService.buffers.alt ? 'none' : 'block'; })); this.register(this._renderService.onRenderedBufferChange(() => this._queueRefresh())); - this.register(this._renderService.onDimensionsChange(() => this._queueRefresh())); - this.register(addDisposableDomListener(window, 'resize', () => this._queueRefresh())); + this.register(this._renderService.onDimensionsChange(() => this._queueRefresh(true))); + this.register(addDisposableDomListener(window, 'resize', () => this._queueRefresh(true))); this.register(this._decorationService.onDecorationRegistered(() => this._queueRefresh())); this.register(this._decorationService.onDecorationRemoved(decoration => this._removeDecoration(decoration))); this.register(this._optionsService.onOptionChange(o => { @@ -91,12 +88,14 @@ export class OverviewRulerRenderer extends Disposable { ); } - private _refreshDecorations(): void { - this._canvas.style.width = `${this._width}px`; - this._canvas.style.height = `${this._screenElement.clientHeight}px`; - this._canvas.width = Math.floor((this._width)* window.devicePixelRatio); - this._canvas.height = Math.floor(this._screenElement.clientHeight * window.devicePixelRatio); - + private _refreshDecorations(updateCanvasDimensions?: boolean): void { + if (updateCanvasDimensions) { + this._canvas.style.width = `${this._width}px`; + this._canvas.style.height = `${this._screenElement.clientHeight}px`; + this._canvas.width = Math.floor((this._width)* window.devicePixelRatio); + this._canvas.height = Math.floor(this._screenElement.clientHeight * window.devicePixelRatio); + } + this._ctx.clearRect(0, 0, this._canvas.width, this._canvas.height); for (const decoration of this._decorationService.decorations) { this._renderDecoration(decoration); } @@ -111,12 +110,12 @@ export class OverviewRulerRenderer extends Disposable { decoration.onRenderEmitter.fire(this._canvas); } - private _queueRefresh(): void { + private _queueRefresh(updateCanvasDimensions?: boolean): void { if (this._animationFrame !== undefined) { return; } this._animationFrame = window.requestAnimationFrame(() => { - this._refreshDecorations(); + this._refreshDecorations(updateCanvasDimensions); this._animationFrame = undefined; }); }