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

Check for disposed before sending update message #13454

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions packages/core/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ export class TabBarToolbar extends ReactWidget {

@postConstruct()
protected init(): void {
this.toDispose.push(this.keybindings.onKeybindingsChanged(() => this.update()));
this.toDispose.push(this.keybindings.onKeybindingsChanged(() => this.maybeUpdate()));

this.toDispose.push(this.contextKeyService.onDidChange(e => {
if (e.affects(this.keybindingContextKeys)) {
this.update();
this.maybeUpdate();
}
}));
}
Expand All @@ -90,7 +90,7 @@ export class TabBarToolbar extends ReactWidget {
if ('command' in item) {
this.commands.getAllHandlers(item.command).forEach(handler => {
if (handler.onDidChangeEnabled) {
this.toDisposeOnUpdateItems.push(handler.onDidChangeEnabled(() => this.update()));
this.toDisposeOnUpdateItems.push(handler.onDidChangeEnabled(() => this.maybeUpdate()));
}
});
}
Expand All @@ -113,7 +113,7 @@ export class TabBarToolbar extends ReactWidget {
} else {
this.hide();
}
this.update();
this.maybeUpdate();
}

updateTarget(current?: Widget): void {
Expand All @@ -130,7 +130,7 @@ export class TabBarToolbar extends ReactWidget {
if (current) {
const resetCurrent = () => {
this.setCurrent(undefined);
this.update();
this.maybeUpdate();
};
current.disposed.connect(resetCurrent);
this.toDisposeOnSetCurrent.push(Disposable.create(() =>
Expand All @@ -144,7 +144,7 @@ export class TabBarToolbar extends ReactWidget {
if (contextKeys.size > 0) {
this.contextKeyListener = this.contextKeyService.onDidChange(event => {
if (event.affects(contextKeys)) {
this.update();
this.maybeUpdate();
}
});
}
Expand Down Expand Up @@ -321,8 +321,8 @@ export class TabBarToolbar extends ReactWidget {
protected renderMenuItem(item: TabBarToolbarItem & MenuToolbarItem): React.ReactNode {
const icon = typeof item.icon === 'function' ? item.icon() : item.icon ?? 'ellipsis';
return <div key={item.id}
className={TabBarToolbar.Styles.TAB_BAR_TOOLBAR_ITEM + ' enabled menu'}
onClick={this.showPopupMenu.bind(this, item.menuPath)}>
className={TabBarToolbar.Styles.TAB_BAR_TOOLBAR_ITEM + ' enabled menu'}
onClick={this.showPopupMenu.bind(this, item.menuPath)}>
<div id={item.id} className={codicon(icon, true)}
title={item.text} />
<div className={codicon('chevron-down') + ' chevron'} />
Expand Down Expand Up @@ -397,9 +397,15 @@ export class TabBarToolbar extends ReactWidget {
} else if (item.menuPath) {
this.renderMoreContextMenu(this.toAnchor(e), item.menuPath);
}
this.update();
this.maybeUpdate();
};

protected maybeUpdate(): void {
if (!this.isDisposed) {
this.update();
}
}

protected onMouseDownEvent = (e: React.MouseEvent<HTMLElement>) => {
if (e.button === 0) {
e.currentTarget.classList.add('active');
Expand All @@ -419,5 +425,4 @@ export namespace TabBarToolbar {
export const TAB_BAR_TOOLBAR_ITEM = 'item';

}

}
Loading