Skip to content

Commit

Permalink
Fix leaks in terminalTabsList
Browse files Browse the repository at this point in the history
Fixes #207462
  • Loading branch information
Tyriar committed Apr 2, 2024
1 parent 32d5ad5 commit b695a62
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/vs/workbench/contrib/terminal/browser/terminalTabsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,16 @@ export class TerminalTabList extends WorkbenchList<ITerminalInstance> {

// Dispose of instance listeners on shutdown to avoid extra work and so tabs don't disappear
// briefly
lifecycleService.onWillShutdown(e => {
this.disposables.add(lifecycleService.onWillShutdown(e => {
dispose(instanceDisposables);
});
instanceDisposables.length = 0;
}));
this.disposables.add(toDisposable(() => {
dispose(instanceDisposables);
instanceDisposables.length = 0;
}));

this.onMouseDblClick(async e => {
this.disposables.add(this.onMouseDblClick(async e => {
const focus = this.getFocus();
if (focus.length === 0) {
const instance = await this._terminalService.createTerminal({ location: TerminalLocation.Panel });
Expand All @@ -149,11 +154,11 @@ export class TerminalTabList extends WorkbenchList<ITerminalInstance> {
if (this._getFocusMode() === 'doubleClick' && this.getFocus().length === 1) {
e.element?.focus(true);
}
});
}));

// on left click, if focus mode = single click, focus the element
// unless multi-selection is in progress
this.onMouseClick(async e => {
this.disposables.add(this.onMouseClick(async e => {
if (this._terminalService.getEditingTerminal()?.instanceId === e.element?.instanceId) {
return;
}
Expand All @@ -165,11 +170,11 @@ export class TerminalTabList extends WorkbenchList<ITerminalInstance> {
e.element?.focus(true);
}
}
});
}));

// on right click, set the focus to that element
// unless multi-selection is in progress
this.onContextMenu(e => {
this.disposables.add(this.onContextMenu(e => {
if (!e.element) {
this.setSelection([]);
return;
Expand All @@ -178,15 +183,15 @@ export class TerminalTabList extends WorkbenchList<ITerminalInstance> {
if (!selection || !selection.find(s => e.element === s)) {
this.setFocus(e.index !== undefined ? [e.index] : []);
}
});
}));

this._terminalTabsSingleSelectedContextKey = TerminalContextKeys.tabsSingularSelection.bindTo(contextKeyService);
this._isSplitContextKey = TerminalContextKeys.splitTerminal.bindTo(contextKeyService);

this.onDidChangeSelection(e => this._updateContextKey());
this.onDidChangeFocus(() => this._updateContextKey());
this.disposables.add(this.onDidChangeSelection(e => this._updateContextKey()));
this.disposables.add(this.onDidChangeFocus(() => this._updateContextKey()));

this.onDidOpen(async e => {
this.disposables.add(this.onDidOpen(async e => {
const instance = e.element;
if (!instance) {
return;
Expand All @@ -195,7 +200,7 @@ export class TerminalTabList extends WorkbenchList<ITerminalInstance> {
if (!e.editorOptions.preserveFocus) {
await instance.focusWhenReady();
}
});
}));
if (!this._decorationsProvider) {
this._decorationsProvider = this.disposables.add(instantiationService.createInstance(TabDecorationsProvider));
this.disposables.add(decorationsService.registerDecorationsProvider(this._decorationsProvider));
Expand Down

0 comments on commit b695a62

Please sign in to comment.