Merge pull request #189345 from microsoft/aamunger/notebookErrorState

not dirty if auto-save soon without any save error state
This commit is contained in:
Aaron Munger
2023-07-31 15:14:18 -07:00
committed by GitHub
4 changed files with 38 additions and 2 deletions
@@ -796,6 +796,8 @@ export interface INotebookEditorModel extends IEditorModel {
readonly resource: URI;
readonly viewType: string;
readonly notebook: INotebookTextModel | undefined;
readonly hasErrorState: boolean;
readonly hasConflictState: boolean;
isResolved(): this is IResolvedNotebookEditorModel;
isDirty(): boolean;
isModified(): boolean;
@@ -24,7 +24,7 @@ import { VSBuffer } from 'vs/base/common/buffer';
import { IWorkingCopyIdentifier } from 'vs/workbench/services/workingCopy/common/workingCopy';
import { NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookProvider';
import { NotebookPerfMarks } from 'vs/workbench/contrib/notebook/common/notebookPerformance';
import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
import { AutoSaveMode, IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { localize } from 'vs/nls';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
@@ -156,6 +156,16 @@ export class NotebookEditorInput extends AbstractResourceEditorInput {
return this._editorModelReference.object.isDirty();
}
override isSaving(): boolean {
const model = this._editorModelReference?.object;
if (!model || !model.isDirty() || model.hasErrorState || model.hasConflictState) {
return false; // require the model to be dirty and not in error or conflict state
}
// if a short auto save is configured, treat this as being saved
return this.filesConfigurationService.getAutoSaveMode() === AutoSaveMode.AFTER_SHORT_DELAY;
}
override async save(group: GroupIdentifier, options?: ISaveOptions): Promise<EditorInput | IUntypedEditorInput | undefined> {
if (this._editorModelReference) {
@@ -108,6 +108,22 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
}
}
get hasErrorState(): boolean {
if (this._workingCopy && 'hasState' in this._workingCopy) {
return this._workingCopy.hasState(StoredFileWorkingCopyState.ERROR);
}
return false;
}
get hasConflictState(): boolean {
if (this._workingCopy && 'hasState' in this._workingCopy) {
return this._workingCopy.hasState(StoredFileWorkingCopyState.CONFLICT);
}
return false;
}
revert(options?: IRevertOptions): Promise<void> {
assertType(this.isResolved());
return this._workingCopy!.revert(options);
@@ -133,7 +149,7 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
this._workingCopyListeners.add(this._workingCopy.onDidChangeOrphaned(() => this._onDidChangeOrphaned.fire()));
this._workingCopyListeners.add(this._workingCopy.onDidChangeReadonly(() => this._onDidChangeReadonly.fire()));
}
this._workingCopy.onDidChangeDirty(() => this._onDidChangeDirty.fire(), undefined, this._workingCopyListeners);
this._workingCopyListeners.add(this._workingCopy.onDidChangeDirty(() => this._onDidChangeDirty.fire(), undefined, this._workingCopyListeners));
this._workingCopyListeners.add(this._workingCopy.onWillDispose(() => {
this._workingCopyListeners.clear();
@@ -135,6 +135,14 @@ export class NotebookEditorTestModel extends EditorModel implements INotebookEdi
return this._dirty;
}
get hasErrorState() {
return false;
}
get hasConflictState() {
return false;
}
isModified(): boolean {
return this._dirty;
}