Skip to content

Commit d70a96a

Browse files
committed
cancel token in the webview
1 parent 6bb525e commit d70a96a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/notebooks/deepnote/selectInputSettingsWebview.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
CancellationToken,
23
Disposable,
34
NotebookCell,
45
NotebookEdit,
@@ -33,7 +34,7 @@ export class SelectInputSettingsWebviewProvider {
3334
/**
3435
* Show the select input settings webview
3536
*/
36-
public async show(cell: NotebookCell): Promise<SelectInputSettings | null> {
37+
public async show(cell: NotebookCell, token?: CancellationToken): Promise<SelectInputSettings | null> {
3738
this.currentCell = cell;
3839

3940
const column = window.activeTextEditor ? window.activeTextEditor.viewColumn : ViewColumn.One;
@@ -77,6 +78,21 @@ export class SelectInputSettingsWebviewProvider {
7778
this.disposables
7879
);
7980

81+
// Handle cancellation token if provided
82+
let cancellationDisposable: Disposable | undefined;
83+
if (token) {
84+
cancellationDisposable = token.onCancellationRequested(() => {
85+
// Only handle cancellation if this is still the current panel
86+
if (this.currentPanelId === panelId) {
87+
if (this.resolvePromise) {
88+
this.resolvePromise(null);
89+
this.resolvePromise = undefined;
90+
}
91+
this.currentPanel?.dispose();
92+
}
93+
});
94+
}
95+
8096
// Reset when the current panel is closed
8197
// Guard with panel identity to prevent old panels from affecting new ones
8298
this.currentPanel.onDidDispose(
@@ -89,6 +105,8 @@ export class SelectInputSettingsWebviewProvider {
89105
this.resolvePromise(null);
90106
this.resolvePromise = undefined;
91107
}
108+
// Clean up cancellation listener
109+
cancellationDisposable?.dispose();
92110
this.disposables.forEach((d) => d.dispose());
93111
this.disposables.length = 0;
94112
}

0 commit comments

Comments
 (0)