Skip to content

Commit ec02bab

Browse files
committed
Use MutableDisposable in CursorRenderLayer
1 parent 94ed3e8 commit ec02bab

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

addons/xterm-addon-canvas/src/CursorRenderLayer.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { CursorBlinkStateManager } from 'browser/renderer/shared/CursorBlinkStat
77
import { IRenderDimensions, IRequestRedrawEvent } from 'browser/renderer/shared/Types';
88
import { ICoreBrowserService, IThemeService } from 'browser/services/Services';
99
import { IEventEmitter } from 'common/EventEmitter';
10-
import { toDisposable } from 'common/Lifecycle';
10+
import { MutableDisposable } from 'common/Lifecycle';
1111
import { isFirefox } from 'common/Platform';
1212
import { ICellData } from 'common/Types';
1313
import { CellData } from 'common/buffer/CellData';
@@ -26,7 +26,7 @@ interface ICursorState {
2626
export class CursorRenderLayer extends BaseRenderLayer {
2727
private _state: ICursorState;
2828
private _cursorRenderers: {[key: string]: (x: number, y: number, cell: ICellData) => void};
29-
private _cursorBlinkStateManager: CursorBlinkStateManager | undefined;
29+
private _cursorBlinkStateManager: MutableDisposable<CursorBlinkStateManager> = this.register(new MutableDisposable());
3030
private _cell: ICellData = new CellData();
3131

3232
constructor(
@@ -57,10 +57,6 @@ export class CursorRenderLayer extends BaseRenderLayer {
5757
};
5858
this.register(optionsService.onOptionChange(() => this._handleOptionsChanged()));
5959
this._handleOptionsChanged();
60-
this.register(toDisposable(() => {
61-
this._cursorBlinkStateManager?.dispose();
62-
this._cursorBlinkStateManager = undefined;
63-
}));
6460
}
6561

6662
public resize(dim: IRenderDimensions): void {
@@ -77,43 +73,42 @@ export class CursorRenderLayer extends BaseRenderLayer {
7773

7874
public reset(): void {
7975
this._clearCursor();
80-
this._cursorBlinkStateManager?.restartBlinkAnimation();
76+
this._cursorBlinkStateManager.value?.restartBlinkAnimation();
8177
this._handleOptionsChanged();
8278
}
8379

8480
public handleBlur(): void {
85-
this._cursorBlinkStateManager?.pause();
81+
this._cursorBlinkStateManager.value?.pause();
8682
this._onRequestRedraw.fire({ start: this._bufferService.buffer.y, end: this._bufferService.buffer.y });
8783
}
8884

8985
public handleFocus(): void {
90-
this._cursorBlinkStateManager?.resume();
86+
this._cursorBlinkStateManager.value?.resume();
9187
this._onRequestRedraw.fire({ start: this._bufferService.buffer.y, end: this._bufferService.buffer.y });
9288
}
9389

9490
private _handleOptionsChanged(): void {
9591
if (this._optionsService.rawOptions.cursorBlink) {
96-
if (!this._cursorBlinkStateManager) {
97-
this._cursorBlinkStateManager = new CursorBlinkStateManager(() => this._render(true), this._coreBrowserService);
92+
if (!this._cursorBlinkStateManager.value) {
93+
this._cursorBlinkStateManager.value = new CursorBlinkStateManager(() => this._render(true), this._coreBrowserService);
9894
}
9995
} else {
100-
this._cursorBlinkStateManager?.dispose();
101-
this._cursorBlinkStateManager = undefined;
96+
this._cursorBlinkStateManager.clear();
10297
}
10398
// Request a refresh from the terminal as management of rendering is being
10499
// moved back to the terminal
105100
this._onRequestRedraw.fire({ start: this._bufferService.buffer.y, end: this._bufferService.buffer.y });
106101
}
107102

108103
public handleCursorMove(): void {
109-
this._cursorBlinkStateManager?.restartBlinkAnimation();
104+
this._cursorBlinkStateManager.value?.restartBlinkAnimation();
110105
}
111106

112107
public handleGridChanged(startRow: number, endRow: number): void {
113-
if (!this._cursorBlinkStateManager || this._cursorBlinkStateManager.isPaused) {
108+
if (!this._cursorBlinkStateManager.value || this._cursorBlinkStateManager.value.isPaused) {
114109
this._render(false);
115110
} else {
116-
this._cursorBlinkStateManager.restartBlinkAnimation();
111+
this._cursorBlinkStateManager.value.restartBlinkAnimation();
117112
}
118113
}
119114

@@ -159,7 +154,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
159154
}
160155

161156
// Don't draw the cursor if it's blinking
162-
if (this._cursorBlinkStateManager && !this._cursorBlinkStateManager.isCursorVisible) {
157+
if (this._cursorBlinkStateManager.value && !this._cursorBlinkStateManager.value.isCursorVisible) {
163158
this._clearCursor();
164159
return;
165160
}

0 commit comments

Comments
 (0)