66import { toRGBA8888 } from 'sixel/lib/Colors' ;
77import { IDisposable } from 'xterm' ;
88import { ICellSize , ITerminalExt , IImageSpec , IRenderDimensions , IRenderService } from './Types' ;
9- import { MutableDisposable } from 'common/Lifecycle' ;
9+ import { Disposable , MutableDisposable , toDisposable } from 'common/Lifecycle' ;
1010
1111
1212const PLACEHOLDER_LENGTH = 4096 ;
@@ -18,12 +18,12 @@ const PLACEHOLDER_HEIGHT = 24;
1818 * - add canvas layer to DOM (browser only for now)
1919 * - draw image tiles onRender
2020 */
21- export class ImageRenderer implements IDisposable {
21+ export class ImageRenderer extends Disposable implements IDisposable {
2222 public canvas : HTMLCanvasElement | undefined ;
2323 private _ctx : CanvasRenderingContext2D | null | undefined ;
2424 private _placeholder : HTMLCanvasElement | undefined ;
2525 private _placeholderBitmap : ImageBitmap | undefined ;
26- private _optionsRefresh = new MutableDisposable ( ) ;
26+ private _optionsRefresh = this . register ( new MutableDisposable ( ) ) ;
2727 private _oldOpen : ( ( parent : HTMLElement ) => void ) | undefined ;
2828 private _renderService : IRenderService | undefined ;
2929 private _oldSetRenderer : ( ( renderer : any ) => void ) | undefined ;
@@ -69,6 +69,7 @@ export class ImageRenderer implements IDisposable {
6969
7070
7171 constructor ( private _terminal : ITerminalExt ) {
72+ super ( ) ;
7273 this . _oldOpen = this . _terminal . _core . open ;
7374 this . _terminal . _core . open = ( parent : HTMLElement ) : void => {
7475 this . _oldOpen ?. call ( this . _terminal . _core , parent ) ;
@@ -84,25 +85,23 @@ export class ImageRenderer implements IDisposable {
8485 this . _renderService ?. refreshRows ( 0 , this . _terminal . rows ) ;
8586 }
8687 } ) ;
87- }
88-
89-
90- public dispose ( ) : void {
91- this . removeLayerFromDom ( ) ;
92- if ( this . _terminal . _core && this . _oldOpen ) {
93- this . _terminal . _core . open = this . _oldOpen ;
94- this . _oldOpen = undefined ;
95- }
96- if ( this . _renderService && this . _oldSetRenderer ) {
97- this . _renderService . setRenderer = this . _oldSetRenderer ;
98- this . _oldSetRenderer = undefined ;
99- }
100- this . _renderService = undefined ;
101- this . canvas = undefined ;
102- this . _ctx = undefined ;
103- this . _placeholderBitmap ?. close ( ) ;
104- this . _placeholderBitmap = undefined ;
105- this . _placeholder = undefined ;
88+ this . register ( toDisposable ( ( ) => {
89+ this . removeLayerFromDom ( ) ;
90+ if ( this . _terminal . _core && this . _oldOpen ) {
91+ this . _terminal . _core . open = this . _oldOpen ;
92+ this . _oldOpen = undefined ;
93+ }
94+ if ( this . _renderService && this . _oldSetRenderer ) {
95+ this . _renderService . setRenderer = this . _oldSetRenderer ;
96+ this . _oldSetRenderer = undefined ;
97+ }
98+ this . _renderService = undefined ;
99+ this . canvas = undefined ;
100+ this . _ctx = undefined ;
101+ this . _placeholderBitmap ?. close ( ) ;
102+ this . _placeholderBitmap = undefined ;
103+ this . _placeholder = undefined ;
104+ } ) ) ;
106105 }
107106
108107 /**
0 commit comments