dispose editor input if an untitled model is reverted

This commit is contained in:
aamunger
2023-06-21 14:24:15 -07:00
parent 343c389b54
commit d9ea96c2ab
4 changed files with 6 additions and 2 deletions
@@ -792,6 +792,7 @@ export interface INotebookEditorModel extends IEditorModel {
readonly onDidSave: Event<IWorkingCopySaveEvent>;
readonly onDidChangeOrphaned: Event<void>;
readonly onDidChangeReadonly: Event<void>;
readonly onDidRevertUntitled: Event<void>;
readonly resource: URI;
readonly viewType: string;
readonly notebook: INotebookTextModel | undefined;
@@ -290,6 +290,7 @@ export class NotebookEditorInput extends AbstractResourceEditorInput {
}
this._register(this._editorModelReference.object.onDidChangeDirty(() => this._onDidChangeDirty.fire()));
this._register(this._editorModelReference.object.onDidChangeReadonly(() => this._onDidChangeCapabilities.fire()));
this._register(this._editorModelReference.object.onDidRevertUntitled(() => this.dispose()));
if (this._editorModelReference.object.isDirty()) {
this._onDidChangeDirty.fire();
}
@@ -19,7 +19,6 @@ import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/no
import { ICellDto2, INotebookEditorModel, INotebookLoadOptions, IResolvedNotebookEditorModel, NotebookCellsChangeType, NotebookData } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookSerializer, INotebookService, SimpleNotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookService';
import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { IFileWorkingCopyManager } from 'vs/workbench/services/workingCopy/common/fileWorkingCopyManager';
import { IStoredFileWorkingCopy, IStoredFileWorkingCopyModel, IStoredFileWorkingCopyModelContentChangedEvent, IStoredFileWorkingCopyModelFactory, IStoredFileWorkingCopySaveEvent, StoredFileWorkingCopyState } from 'vs/workbench/services/workingCopy/common/storedFileWorkingCopy';
import { IUntitledFileWorkingCopy, IUntitledFileWorkingCopyModel, IUntitledFileWorkingCopyModelContentChangedEvent, IUntitledFileWorkingCopyModelFactory } from 'vs/workbench/services/workingCopy/common/untitledFileWorkingCopy';
@@ -33,11 +32,13 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
private readonly _onDidSave = this._register(new Emitter<IStoredFileWorkingCopySaveEvent>());
private readonly _onDidChangeOrphaned = this._register(new Emitter<void>());
private readonly _onDidChangeReadonly = this._register(new Emitter<void>());
private readonly _onDidRevertUntitled = this._register(new Emitter<void>());
readonly onDidChangeDirty: Event<void> = this._onDidChangeDirty.event;
readonly onDidSave: Event<IStoredFileWorkingCopySaveEvent> = this._onDidSave.event;
readonly onDidChangeOrphaned: Event<void> = this._onDidChangeOrphaned.event;
readonly onDidChangeReadonly: Event<void> = this._onDidChangeReadonly.event;
readonly onDidRevertUntitled: Event<void> = this._onDidRevertUntitled.event;
private _workingCopy?: IStoredFileWorkingCopy<NotebookFileWorkingCopyModel> | IUntitledFileWorkingCopy<NotebookFileWorkingCopyModel>;
private readonly _workingCopyListeners = this._register(new DisposableStore());
@@ -48,7 +49,6 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
private readonly _hasAssociatedFilePath: boolean,
readonly viewType: string,
private readonly _workingCopyManager: IFileWorkingCopyManager<NotebookFileWorkingCopyModel, NotebookFileWorkingCopyModel>,
@ILifecycleService lifecycleService: ILifecycleService,
@IFilesConfigurationService private readonly _filesConfigurationService: IFilesConfigurationService
) {
super();
@@ -119,6 +119,7 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
} else {
this._workingCopy = await this._workingCopyManager.resolve({ untitledResource: this.resource, isScratchpad: this.scratchPad });
}
this._workingCopy.onDidRevert(() => this._onDidRevertUntitled.fire());
} else {
this._workingCopy = await this._workingCopyManager.resolve(this.resource, options?.forceReadFromFile ? { reload: { async: false, force: true } } : undefined);
this._workingCopyListeners.add(this._workingCopy.onDidSave(e => this._onDidSave.fire(e)));
@@ -87,6 +87,7 @@ export class NotebookEditorTestModel extends EditorModel implements INotebookEdi
readonly onDidChangeOrphaned = Event.None;
readonly onDidChangeReadonly = Event.None;
readonly onDidRevertUntitled = Event.None;
private readonly _onDidChangeContent = this._register(new Emitter<void>());
readonly onDidChangeContent: Event<void> = this._onDidChangeContent.event;