mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Editor view state is too sticky for diff editors (fix #134098)
This commit is contained in:
parent
0e11dc34f4
commit
57903bcf3f
|
@ -4,6 +4,7 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { IEditorMemento, IEditorCloseEvent, IEditorOpenContext, EditorResourceAccessor, SideBySideEditor } from 'vs/workbench/common/editor';
|
||||
import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
|
@ -14,7 +15,7 @@ import { ITextResourceConfigurationService } from 'vs/editor/common/services/tex
|
|||
import { IEditorGroupsService, IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IExtUri } from 'vs/base/common/resources';
|
||||
import { MutableDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IDisposable, MutableDisposable } from 'vs/base/common/lifecycle';
|
||||
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
|
||||
import { IEditorOptions } from 'vs/platform/editor/common/editor';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
|
@ -28,6 +29,8 @@ export abstract class AbstractEditorWithViewState<T extends object> extends Edit
|
|||
|
||||
private readonly groupListener = this._register(new MutableDisposable());
|
||||
|
||||
private editorViewStateDisposables: Map<EditorInput, IDisposable> | undefined;
|
||||
|
||||
constructor(
|
||||
id: string,
|
||||
viewStateStorageKey: string,
|
||||
|
@ -96,6 +99,22 @@ export abstract class AbstractEditorWithViewState<T extends object> extends Edit
|
|||
return; // we need a resource
|
||||
}
|
||||
|
||||
// If we are not tracking disposed editor view state
|
||||
// make sure to clear the view state once the editor
|
||||
// is disposed.
|
||||
if (!this.tracksDisposedEditorViewState()) {
|
||||
if (!this.editorViewStateDisposables) {
|
||||
this.editorViewStateDisposables = new Map<EditorInput, IDisposable>();
|
||||
}
|
||||
|
||||
if (!this.editorViewStateDisposables.has(input)) {
|
||||
this.editorViewStateDisposables.set(input, Event.once(input.onWillDispose)(() => {
|
||||
this.clearEditorViewState(resource, this.group);
|
||||
this.editorViewStateDisposables?.delete(input);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// Clear the editor view state if:
|
||||
// - the editor view state should not be tracked for disposed editors
|
||||
// - the user configured to not restore view state unless the editor is still opened in the group
|
||||
|
@ -179,6 +198,18 @@ export abstract class AbstractEditorWithViewState<T extends object> extends Edit
|
|||
this.viewState.clearEditorState(resource, group);
|
||||
}
|
||||
|
||||
override dispose(): void {
|
||||
super.dispose();
|
||||
|
||||
if (this.editorViewStateDisposables) {
|
||||
for (const [, disposables] of this.editorViewStateDisposables) {
|
||||
disposables.dispose();
|
||||
}
|
||||
|
||||
this.editorViewStateDisposables = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
//#region Subclasses should/could override based on needs
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue