Skip to content

Commit 2baf8c5

Browse files
authored
Prevent multiple cell status bar items (microsoft#185621)
* Stop running Throttler after class is disposed Fix microsoft/vscode-jupyter#13537 * Clean up item ID cache * Add comment
1 parent a0b88b5 commit 2baf8c5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/contributedStatusBarItemController.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class CellStatusBarHelper extends Disposable {
7676
private _currentItemLists: INotebookCellStatusBarItemList[] = [];
7777

7878
private _activeToken: CancellationTokenSource | undefined;
79+
private _isDisposed: boolean = false;
7980

8081
private readonly _updateThrottler = new Throttler();
8182

@@ -101,7 +102,18 @@ class CellStatusBarHelper extends Disposable {
101102
private _updateSoon(): void {
102103
// Wait a tick to make sure that the event is fired to the EH before triggering status bar providers
103104
this._register(disposableTimeout(() => {
104-
this._updateThrottler.queue(() => this._update());
105+
this._updateThrottler.queue(async () => {
106+
if (this._isDisposed) {
107+
// This order of events can happen
108+
// - Start one update
109+
// - Start a second update, its queued
110+
// - This class is disposed, cancelling the first update
111+
// - The second update runs, and we're disposed. So bail at this point.
112+
return;
113+
}
114+
115+
return this._update();
116+
});
105117
}, 0));
106118
}
107119

@@ -128,6 +140,7 @@ class CellStatusBarHelper extends Disposable {
128140

129141
override dispose() {
130142
super.dispose();
143+
this._isDisposed = true;
131144
this._activeToken?.dispose(true);
132145

133146
this._notebookViewModel.deltaCellStatusBarItems(this._currentItemIds, [{ handle: this._cell.handle, items: [] }]);

src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,8 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
742742
const cell = this.getCellByHandle(itemDelta.handle);
743743
const deleted = deletesByHandle[itemDelta.handle] ?? [];
744744
delete deletesByHandle[itemDelta.handle];
745+
deleted.forEach(id => this._statusBarItemIdToCellMap.delete(id));
746+
745747
const ret = cell?.deltaCellStatusBarItems(deleted, itemDelta.items) || [];
746748
ret.forEach(id => {
747749
this._statusBarItemIdToCellMap.set(id, itemDelta.handle);
@@ -755,6 +757,7 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
755757
const ids = deletesByHandle[handle];
756758
const cell = this.getCellByHandle(handle);
757759
cell?.deltaCellStatusBarItems(ids, []);
760+
ids.forEach(id => this._statusBarItemIdToCellMap.delete(id));
758761
}
759762

760763
return result;

0 commit comments

Comments
 (0)