From 3d41f028e4966eda695a069b2ff1ddeab450a6b6 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 11 May 2022 10:12:48 -0700 Subject: [PATCH 1/4] Layout dimension left/right after renderer dims change Fixes #3773 --- .../Decorations/BufferDecorationRenderer.ts | 23 ++++++++++++++----- src/browser/TestUtils.test.ts | 2 +- src/browser/services/RenderService.ts | 4 ++-- src/browser/services/Services.ts | 1 - 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/browser/Decorations/BufferDecorationRenderer.ts b/src/browser/Decorations/BufferDecorationRenderer.ts index 22dc73e9b0..5bd0f940dd 100644 --- a/src/browser/Decorations/BufferDecorationRenderer.ts +++ b/src/browser/Decorations/BufferDecorationRenderer.ts @@ -14,6 +14,7 @@ export class BufferDecorationRenderer extends Disposable { private _animationFrame: number | undefined; private _altBufferIsActive: boolean = false; + private _dimensionsChanged: boolean = false; constructor( private readonly _screenElement: HTMLElement, @@ -28,7 +29,10 @@ export class BufferDecorationRenderer extends Disposable { this._screenElement.appendChild(this._container); this.register(this._renderService.onRenderedBufferChange(() => this._queueRefresh())); - this.register(this._renderService.onDimensionsChange(() => this._queueRefresh())); + this.register(this._renderService.onDimensionsChange(() => { + this._dimensionsChanged = true; + this._queueRefresh(); + })); this.register(addDisposableDomListener(window, 'resize', () => this._queueRefresh())); this.register(this._bufferService.buffers.onBufferActivate(() => { this._altBufferIsActive = this._bufferService.buffer === this._bufferService.buffers.alt; @@ -70,6 +74,9 @@ export class BufferDecorationRenderer extends Disposable { this._container.appendChild(element); } this._refreshStyle(decoration, element); + if (this._dimensionsChanged) { + this._refreshXPosition(decoration, element); + } decoration.onRenderEmitter.fire(element); } @@ -86,11 +93,7 @@ export class BufferDecorationRenderer extends Disposable { // exceeded the container width, so hide element.style.display = 'none'; } - if ((decoration.options.anchor || 'left') === 'right') { - element.style.right = x ? `${x * this._renderService.dimensions.actualCellWidth}px` : ''; - } else { - element.style.left = x ? `${x * this._renderService.dimensions.actualCellWidth}px` : ''; - } + this._refreshXPosition(decoration, element, x); return element; } @@ -106,6 +109,14 @@ export class BufferDecorationRenderer extends Disposable { } } + private _refreshXPosition(decoration: IInternalDecoration, element: HTMLElement, x: number = decoration.options.x ?? 0): void { + if ((decoration.options.anchor || 'left') === 'right') { + element.style.right = x ? `${x * this._renderService.dimensions.actualCellWidth}px` : ''; + } else { + element.style.left = x ? `${x * this._renderService.dimensions.actualCellWidth}px` : ''; + } + } + private _removeDecoration(decoration: IInternalDecoration): void { this._decorationElements.get(decoration)?.remove(); this._decorationElements.delete(decoration); diff --git a/src/browser/TestUtils.test.ts b/src/browser/TestUtils.test.ts index 85e2bb55b6..cc45f5e489 100644 --- a/src/browser/TestUtils.test.ts +++ b/src/browser/TestUtils.test.ts @@ -396,7 +396,7 @@ export class MockRenderService implements IRenderService { public resize(cols: number, rows: number): void { throw new Error('Method not implemented.'); } - public changeOptions(): void { + public _handleOptionsChanged(): void { throw new Error('Method not implemented.'); } public setRenderer(renderer: IRenderer): void { diff --git a/src/browser/services/RenderService.ts b/src/browser/services/RenderService.ts index 91b510a3fd..b575858aca 100644 --- a/src/browser/services/RenderService.ts +++ b/src/browser/services/RenderService.ts @@ -69,7 +69,7 @@ export class RenderService extends Disposable implements IRenderService { this.register(bufferService.onResize(() => this._fullRefresh())); this.register(bufferService.buffers.onBufferActivate(() => this._renderer?.clear())); - this.register(optionsService.onOptionChange(() => this._renderer.onOptionsChanged())); + this.register(optionsService.onOptionChange(() => this._handleOptionsChanged())); this.register(this._charSizeService.onCharSizeChange(() => this.onCharSizeChanged())); // No need to register this as renderer is explicitly disposed in RenderService.dispose @@ -135,7 +135,7 @@ export class RenderService extends Disposable implements IRenderService { this._fireOnCanvasResize(); } - public changeOptions(): void { + private _handleOptionsChanged(): void { this._renderer.onOptionsChanged(); this.refreshRows(0, this._rowCount - 1); this._fireOnCanvasResize(); diff --git a/src/browser/services/Services.ts b/src/browser/services/Services.ts index 7191d0edd3..a9f76a9097 100644 --- a/src/browser/services/Services.ts +++ b/src/browser/services/Services.ts @@ -61,7 +61,6 @@ export interface IRenderService extends IDisposable { refreshRows(start: number, end: number): void; clearTextureAtlas(): void; resize(cols: number, rows: number): void; - changeOptions(): void; setRenderer(renderer: IRenderer): void; setColors(colors: IColorSet): void; onDevicePixelRatioChange(): void; From aeb4fa0fe9da0d43fc10674aebd36ba4ada9433e Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 11 May 2022 10:15:18 -0700 Subject: [PATCH 2/4] Fix compile after bad merge --- .../Decorations/BufferDecorationRenderer.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/browser/Decorations/BufferDecorationRenderer.ts b/src/browser/Decorations/BufferDecorationRenderer.ts index f548750ae0..e695c82459 100644 --- a/src/browser/Decorations/BufferDecorationRenderer.ts +++ b/src/browser/Decorations/BufferDecorationRenderer.ts @@ -66,7 +66,7 @@ export class BufferDecorationRenderer extends Disposable { private _renderDecoration(decoration: IInternalDecoration): void { this._refreshStyle(decoration); if (this._dimensionsChanged) { - this._refreshXPosition(decoration, element); + this._refreshXPosition(decoration); } } @@ -83,7 +83,7 @@ export class BufferDecorationRenderer extends Disposable { // exceeded the container width, so hide element.style.display = 'none'; } - this._refreshXPosition(decoration, element, x); + this._refreshXPosition(decoration); return element; } @@ -111,11 +111,15 @@ export class BufferDecorationRenderer extends Disposable { } } - private _refreshXPosition(decoration: IInternalDecoration, element: HTMLElement, x: number = decoration.options.x ?? 0): void { + private _refreshXPosition(decoration: IInternalDecoration): void { + if (!decoration.element) { + return; + } + const x = decoration.options.x ?? 0; if ((decoration.options.anchor || 'left') === 'right') { - element.style.right = x ? `${x * this._renderService.dimensions.actualCellWidth}px` : ''; + decoration.element.style.right = x ? `${x * this._renderService.dimensions.actualCellWidth}px` : ''; } else { - element.style.left = x ? `${x * this._renderService.dimensions.actualCellWidth}px` : ''; + decoration.element.style.left = x ? `${x * this._renderService.dimensions.actualCellWidth}px` : ''; } } From 0976b15709f7dd7649c4471a6e59349d4ace8787 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 11 May 2022 11:57:13 -0700 Subject: [PATCH 3/4] Fix lint --- src/browser/TestUtils.test.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/browser/TestUtils.test.ts b/src/browser/TestUtils.test.ts index cc45f5e489..cb487dbc6a 100644 --- a/src/browser/TestUtils.test.ts +++ b/src/browser/TestUtils.test.ts @@ -396,9 +396,6 @@ export class MockRenderService implements IRenderService { public resize(cols: number, rows: number): void { throw new Error('Method not implemented.'); } - public _handleOptionsChanged(): void { - throw new Error('Method not implemented.'); - } public setRenderer(renderer: IRenderer): void { throw new Error('Method not implemented.'); } From f18528d2bb82dc45bd51c1a2c835290ef7f699dc Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Thu, 12 May 2022 10:58:50 -0700 Subject: [PATCH 4/4] Clear _dimensionsChanged variable --- src/browser/Decorations/BufferDecorationRenderer.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/browser/Decorations/BufferDecorationRenderer.ts b/src/browser/Decorations/BufferDecorationRenderer.ts index e695c82459..a063f9bd8b 100644 --- a/src/browser/Decorations/BufferDecorationRenderer.ts +++ b/src/browser/Decorations/BufferDecorationRenderer.ts @@ -61,6 +61,7 @@ export class BufferDecorationRenderer extends Disposable { for (const decoration of this._decorationService.decorations) { this._renderDecoration(decoration); } + this._dimensionsChanged = false; } private _renderDecoration(decoration: IInternalDecoration): void {