@@ -23,6 +23,7 @@ import { logger } from '../../platform/logging';
2323@injectable ( )
2424export class SelectInputSettingsWebviewProvider {
2525 private currentPanel : WebviewPanel | undefined ;
26+ private currentPanelId : number = 0 ;
2627 private readonly disposables : Disposable [ ] = [ ] ;
2728 private currentCell : NotebookCell | undefined ;
2829 private resolvePromise : ( ( settings : SelectInputSettings | null ) => void ) | undefined ;
@@ -37,11 +38,21 @@ export class SelectInputSettingsWebviewProvider {
3738
3839 const column = window . activeTextEditor ? window . activeTextEditor . viewColumn : ViewColumn . One ;
3940
40- // If we already have a panel, dispose it and create a new one
41+ // If we already have a panel, cancel any outstanding operation before disposing
4142 if ( this . currentPanel ) {
43+ // Cancel the previous operation by resolving with null
44+ if ( this . resolvePromise ) {
45+ this . resolvePromise ( null ) ;
46+ this . resolvePromise = undefined ;
47+ }
48+ // Now dispose the old panel
4249 this . currentPanel . dispose ( ) ;
4350 }
4451
52+ // Increment panel ID to track this specific panel instance
53+ this . currentPanelId ++ ;
54+ const panelId = this . currentPanelId ;
55+
4556 // Create a new panel
4657 this . currentPanel = window . createWebviewPanel (
4758 'deepnoteSelectInputSettings' ,
@@ -67,16 +78,20 @@ export class SelectInputSettingsWebviewProvider {
6778 ) ;
6879
6980 // Reset when the current panel is closed
81+ // Guard with panel identity to prevent old panels from affecting new ones
7082 this . currentPanel . onDidDispose (
7183 ( ) => {
72- this . currentPanel = undefined ;
73- this . currentCell = undefined ;
74- if ( this . resolvePromise ) {
75- this . resolvePromise ( null ) ;
76- this . resolvePromise = undefined ;
84+ // Only handle disposal if this is still the current panel
85+ if ( this . currentPanelId === panelId ) {
86+ this . currentPanel = undefined ;
87+ this . currentCell = undefined ;
88+ if ( this . resolvePromise ) {
89+ this . resolvePromise ( null ) ;
90+ this . resolvePromise = undefined ;
91+ }
92+ this . disposables . forEach ( ( d ) => d . dispose ( ) ) ;
93+ this . disposables . length = 0 ;
7794 }
78- this . disposables . forEach ( ( d ) => d . dispose ( ) ) ;
79- this . disposables . length = 0 ;
8095 } ,
8196 null ,
8297 this . disposables
0 commit comments