Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent multiple cell status bar items #185621

Merged
merged 3 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class CellStatusBarHelper extends Disposable {
private _currentItemLists: INotebookCellStatusBarItemList[] = [];

private _activeToken: CancellationTokenSource | undefined;
private _isDisposed: boolean = false;

private readonly _updateThrottler = new Throttler();

Expand All @@ -101,7 +102,18 @@ class CellStatusBarHelper extends Disposable {
private _updateSoon(): void {
// Wait a tick to make sure that the event is fired to the EH before triggering status bar providers
this._register(disposableTimeout(() => {
this._updateThrottler.queue(() => this._update());
this._updateThrottler.queue(async () => {
if (this._isDisposed) {
// This order of events can happen
// - Start one update
// - Start a second update, its queued
// - This class is disposed, cancelling the first update
// - The second update runs, and we're disposed. So bail at this point.
return;
}

return this._update();
});
}, 0));
}

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

override dispose() {
super.dispose();
this._isDisposed = true;
this._activeToken?.dispose(true);

this._notebookViewModel.deltaCellStatusBarItems(this._currentItemIds, [{ handle: this._cell.handle, items: [] }]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,8 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
const cell = this.getCellByHandle(itemDelta.handle);
const deleted = deletesByHandle[itemDelta.handle] ?? [];
delete deletesByHandle[itemDelta.handle];
deleted.forEach(id => this._statusBarItemIdToCellMap.delete(id));

const ret = cell?.deltaCellStatusBarItems(deleted, itemDelta.items) || [];
ret.forEach(id => {
this._statusBarItemIdToCellMap.set(id, itemDelta.handle);
Expand All @@ -755,6 +757,7 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
const ids = deletesByHandle[handle];
const cell = this.getCellByHandle(handle);
cell?.deltaCellStatusBarItems(ids, []);
ids.forEach(id => this._statusBarItemIdToCellMap.delete(id));
}

return result;
Expand Down