diff --git a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts index 306c11a4567..bde32f2180d 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts @@ -792,6 +792,7 @@ export interface INotebookEditorModel extends IEditorModel { readonly onDidSave: Event; readonly onDidChangeOrphaned: Event; readonly onDidChangeReadonly: Event; + readonly onDidRevertUntitled: Event; readonly resource: URI; readonly viewType: string; readonly notebook: INotebookTextModel | undefined; diff --git a/src/vs/workbench/contrib/notebook/common/notebookEditorInput.ts b/src/vs/workbench/contrib/notebook/common/notebookEditorInput.ts index 4b9186cb43f..9db655f6a63 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookEditorInput.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookEditorInput.ts @@ -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(); } diff --git a/src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts b/src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts index e0c3352be75..2137794c403 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts @@ -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()); private readonly _onDidChangeOrphaned = this._register(new Emitter()); private readonly _onDidChangeReadonly = this._register(new Emitter()); + private readonly _onDidRevertUntitled = this._register(new Emitter()); readonly onDidChangeDirty: Event = this._onDidChangeDirty.event; readonly onDidSave: Event = this._onDidSave.event; readonly onDidChangeOrphaned: Event = this._onDidChangeOrphaned.event; readonly onDidChangeReadonly: Event = this._onDidChangeReadonly.event; + readonly onDidRevertUntitled: Event = this._onDidRevertUntitled.event; private _workingCopy?: IStoredFileWorkingCopy | IUntitledFileWorkingCopy; 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, - @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))); diff --git a/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts b/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts index c9f0a3114c7..6e08e4fdea8 100644 --- a/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts @@ -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()); readonly onDidChangeContent: Event = this._onDidChangeContent.event;