Skip to content

Commit 3b42192

Browse files
committed
not dirty if auto-save soon without any save error state
1 parent 205ea5f commit 3b42192

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

src/vs/workbench/contrib/notebook/common/notebookCommon.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ export interface INotebookEditorModel extends IEditorModel {
796796
readonly resource: URI;
797797
readonly viewType: string;
798798
readonly notebook: INotebookTextModel | undefined;
799+
readonly hasErrorState: boolean;
799800
isResolved(): this is IResolvedNotebookEditorModel;
800801
isDirty(): boolean;
801802
isModified(): boolean;

src/vs/workbench/contrib/notebook/common/notebookEditorInput.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { VSBuffer } from 'vs/base/common/buffer';
2424
import { IWorkingCopyIdentifier } from 'vs/workbench/services/workingCopy/common/workingCopy';
2525
import { NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookProvider';
2626
import { NotebookPerfMarks } from 'vs/workbench/contrib/notebook/common/notebookPerformance';
27-
import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
27+
import { AutoSaveMode, IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
2828
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
2929
import { localize } from 'vs/nls';
3030
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
@@ -156,6 +156,15 @@ export class NotebookEditorInput extends AbstractResourceEditorInput {
156156
return this._editorModelReference.object.isDirty();
157157
}
158158

159+
override isSaving(): boolean {
160+
if (!this._editorModelReference || !this._editorModelReference.object.isDirty() || this._editorModelReference.object.hasErrorState) {
161+
return false; // require the model to be dirty and not in error state
162+
}
163+
164+
// if a short auto save is configured, treat this as being saved
165+
return this.filesConfigurationService.getAutoSaveMode() === AutoSaveMode.AFTER_SHORT_DELAY;
166+
}
167+
159168
override async save(group: GroupIdentifier, options?: ISaveOptions): Promise<EditorInput | IUntypedEditorInput | undefined> {
160169
if (this._editorModelReference) {
161170

src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
4646
private _workingCopy?: IStoredFileWorkingCopy<NotebookFileWorkingCopyModel> | IUntitledFileWorkingCopy<NotebookFileWorkingCopyModel>;
4747
private readonly _workingCopyListeners = this._register(new DisposableStore());
4848
private readonly scratchPad: boolean;
49+
private _hasErrorState: boolean = false;
4950

5051
constructor(
5152
readonly resource: URI,
@@ -108,6 +109,10 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
108109
}
109110
}
110111

112+
get hasErrorState(): boolean {
113+
return this._hasErrorState;
114+
}
115+
111116
revert(options?: IRevertOptions): Promise<void> {
112117
assertType(this.isResolved());
113118
return this._workingCopy!.revert(options);
@@ -118,6 +123,13 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
118123
return this._workingCopy!.save(options);
119124
}
120125

126+
private onDidChangeDirtyHandler() {
127+
if (!this._workingCopy?.isDirty()) {
128+
this._hasErrorState = false;
129+
}
130+
this._onDidChangeDirty.fire();
131+
}
132+
121133
async load(options?: INotebookLoadOptions): Promise<IResolvedNotebookEditorModel> {
122134
if (!this._workingCopy || !this._workingCopy.model) {
123135
if (this.resource.scheme === Schemas.untitled) {
@@ -132,8 +144,9 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
132144
this._workingCopyListeners.add(this._workingCopy.onDidSave(e => this._onDidSave.fire(e)));
133145
this._workingCopyListeners.add(this._workingCopy.onDidChangeOrphaned(() => this._onDidChangeOrphaned.fire()));
134146
this._workingCopyListeners.add(this._workingCopy.onDidChangeReadonly(() => this._onDidChangeReadonly.fire()));
147+
this._workingCopyListeners.add(this._workingCopy.onDidSaveError(() => { this._hasErrorState = true; }));
135148
}
136-
this._workingCopy.onDidChangeDirty(() => this._onDidChangeDirty.fire(), undefined, this._workingCopyListeners);
149+
this._workingCopyListeners.add(this._workingCopy.onDidChangeDirty(this.onDidChangeDirtyHandler.bind(this), undefined, this._workingCopyListeners));
137150

138151
this._workingCopyListeners.add(this._workingCopy.onWillDispose(() => {
139152
this._workingCopyListeners.clear();

src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ export class NotebookEditorTestModel extends EditorModel implements INotebookEdi
135135
return this._dirty;
136136
}
137137

138+
get hasErrorState() {
139+
return false;
140+
}
141+
138142
isModified(): boolean {
139143
return this._dirty;
140144
}

0 commit comments

Comments
 (0)