Skip to content

Commit

Permalink
Check for disposed before sending update message (#13454)
Browse files Browse the repository at this point in the history
fixes #13441

contributed on behalf of STMicroelectronics

Signed-off-by: Thomas Mäder <[email protected]>
  • Loading branch information
tsmaeder authored Mar 22, 2024
1 parent 3cf66f9 commit c2b0704
Showing 1 changed file with 15 additions and 10 deletions.
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';

}

}

0 comments on commit c2b0704

Please sign in to comment.