Skip to content

Commit 0c4ee0d

Browse files
authored
Merge pull request #3769 from Tyriar/145751
Only create decoration elements when they are actually rendered
2 parents 5d09d3b + b7c0332 commit 0c4ee0d

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/browser/Decorations/BufferDecorationRenderer.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,7 @@ export class BufferDecorationRenderer extends Disposable {
6060
}
6161

6262
private _renderDecoration(decoration: IInternalDecoration): void {
63-
let element = this._decorationElements.get(decoration);
64-
if (!element) {
65-
element = this._createElement(decoration);
66-
decoration.onDispose(() => this._removeDecoration(decoration));
67-
decoration.marker.onDispose(() => decoration.dispose());
68-
decoration.element = element;
69-
this._decorationElements.set(decoration, element);
70-
this._container.appendChild(element);
71-
}
72-
this._refreshStyle(decoration, element);
73-
decoration.onRenderEmitter.fire(element);
63+
this._refreshStyle(decoration);
7464
}
7565

7666
private _createElement(decoration: IInternalDecoration): HTMLElement {
@@ -95,14 +85,26 @@ export class BufferDecorationRenderer extends Disposable {
9585
return element;
9686
}
9787

98-
private _refreshStyle(decoration: IInternalDecoration, element: HTMLElement): void {
88+
private _refreshStyle(decoration: IInternalDecoration): void {
9989
const line = decoration.marker.line - this._bufferService.buffers.active.ydisp;
10090
if (line < 0 || line >= this._bufferService.rows) {
10191
// outside of viewport
102-
element.style.display = 'none';
92+
if (decoration.element) {
93+
decoration.element.style.display = 'none';
94+
decoration.onRenderEmitter.fire(decoration.element);
95+
}
10396
} else {
97+
let element = this._decorationElements.get(decoration);
98+
if (!element) {
99+
decoration.onDispose(() => this._removeDecoration(decoration));
100+
element = this._createElement(decoration);
101+
decoration.element = element;
102+
this._decorationElements.set(decoration, element);
103+
this._container.appendChild(element);
104+
}
104105
element.style.top = `${line * this._renderService.dimensions.actualCellHeight}px`;
105106
element.style.display = this._altBufferIsActive ? 'none' : 'block';
107+
decoration.onRenderEmitter.fire(element);
106108
}
107109
}
108110

src/common/services/DecorationService.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ export class DecorationService extends Disposable implements IDecorationService
3030
}
3131
const decoration = new Decoration(options);
3232
if (decoration) {
33+
const markerDispose = decoration.marker.onDispose(() => decoration.dispose());
3334
decoration.onDispose(() => {
3435
if (decoration) {
3536
const index = this._decorations.indexOf(decoration);
3637
if (index >= 0) {
3738
this._decorations.splice(this._decorations.indexOf(decoration), 1);
3839
this._onDecorationRemoved.fire(decoration);
3940
}
41+
markerDispose.dispose();
4042
}
4143
});
4244
this._decorations.push(decoration);

0 commit comments

Comments
 (0)