Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dispose editor input if an untitled model is reverted #185811

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/notebook/common/notebookCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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());
Expand All @@ -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();
Expand Down Expand Up @@ -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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down