debt - fix listener leak in file editor

This commit is contained in:
Benjamin Pasero 2019-01-25 17:05:03 +01:00
parent 48d48a0388
commit 04dd87588e
2 changed files with 11 additions and 1 deletions

View file

@ -118,6 +118,7 @@ export abstract class BaseEditor extends Panel implements IEditor {
setVisible(visible: boolean, group?: IEditorGroup): void {
super.setVisible(visible);
// Propagate to Editor
this.setEditorVisible(visible, group);
}

View file

@ -30,6 +30,7 @@ import { IEditorGroupsService, IEditorGroup } from 'vs/workbench/services/group/
import { CancellationToken } from 'vs/base/common/cancellation';
import { IEditorGroupView } from 'vs/workbench/browser/parts/editor/editor';
import { createErrorWithActions } from 'vs/base/common/errorsWithActions';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
/**
* An implementation of editor for file system resources.
@ -39,6 +40,7 @@ export class TextFileEditor extends BaseTextEditor {
static readonly ID = TEXT_FILE_EDITOR_ID;
private restoreViewState: boolean;
private groupListener: IDisposable;
constructor(
@ITelemetryService telemetryService: ITelemetryService,
@ -96,7 +98,8 @@ export class TextFileEditor extends BaseTextEditor {
// React to editors closing to preserve or clear view state. This needs to happen
// in the onWillCloseEditor because at that time the editor has not yet
// been disposed and we can safely persist the view state still as needed.
this._register((group as IEditorGroupView).onWillCloseEditor(e => {
this.groupListener = dispose(this.groupListener);
this.groupListener = ((group as IEditorGroupView).onWillCloseEditor(e => {
if (e.editor === this.input) {
this.doSaveOrClearTextEditorViewState(this.input);
}
@ -276,4 +279,10 @@ export class TextFileEditor extends BaseTextEditor {
this.saveTextEditorViewState(input.getResource());
}
}
dispose(): void {
this.groupListener = dispose(this.groupListener);
super.dispose();
}
}