@@ -781,17 +781,26 @@ export class PositronPlotsService extends Disposable implements IPositronPlotsSe
781
781
this . _onDidSelectPlot . fire ( plotClient . id ) ;
782
782
}
783
783
784
+ // Dispose the plot client when this service is disposed (we own this
785
+ // object)
786
+ const disp = this . _register ( plotClient ) ;
787
+
784
788
// Remove the plot from our list when it is closed
785
- this . _register ( plotClient . onDidClose ( ( ) => {
786
- const index = this . _plots . indexOf ( plotClient ) ;
787
- if ( index >= 0 ) {
788
- this . _plots . splice ( index , 1 ) ;
789
+ plotClient . register ( {
790
+ dispose : ( ) => {
791
+ const index = this . _plots . indexOf ( plotClient ) ;
792
+ if ( index >= 0 ) {
793
+ this . _plots . splice ( index , 1 ) ;
794
+ }
795
+
796
+ // Clear the plot's metadata from storage
797
+ this . _storageService . remove (
798
+ this . generateStorageKey ( plotClient . metadata . session_id , plotClient . metadata . id , plotClient . metadata . location ) ,
799
+ StorageScope . WORKSPACE ) ;
800
+
801
+ disp . dispose ( ) ;
789
802
}
790
- // Clear the plot's metadata from storage
791
- this . _storageService . remove (
792
- this . generateStorageKey ( plotClient . metadata . session_id , plotClient . metadata . id , plotClient . metadata . location ) ,
793
- StorageScope . WORKSPACE ) ;
794
- } ) ) ;
803
+ } ) ;
795
804
796
805
const selectPlot = ( ) => {
797
806
// Raise the Plots pane so the user can see the updated plot
@@ -803,19 +812,15 @@ export class PositronPlotsService extends Disposable implements IPositronPlotsSe
803
812
} ;
804
813
805
814
// Raise the plot if it's updated by the runtime
806
- this . _register ( plotClient . onDidRenderUpdate ( ( _plot ) => {
815
+ plotClient . register ( plotClient . onDidRenderUpdate ( ( _plot ) => {
807
816
selectPlot ( ) ;
808
817
} ) ) ;
809
818
810
819
// Focus the plot if the runtime requests it
811
- this . _register ( plotClient . onDidShowPlot ( ( ) => {
820
+ plotClient . register ( plotClient . onDidShowPlot ( ( ) => {
812
821
selectPlot ( ) ;
813
822
} ) ) ;
814
-
815
- // Dispose the plot client when this service is disposed (we own this
816
- // object)
817
- this . _register ( plotClient ) ;
818
- }
823
+ }
819
824
820
825
/**
821
826
* Creates a new static plot client instance and registers it with the
0 commit comments