diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 36e0da44c73..403dee7e209 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -484,7 +484,7 @@ export abstract class EditorInput extends Disposable implements IEditorInput { abstract resolve(): Promise; isReadonly(): boolean { - return false; + return true; } isUntitled(): boolean { diff --git a/src/vs/workbench/contrib/files/browser/fileCommands.ts b/src/vs/workbench/contrib/files/browser/fileCommands.ts index 7b5b47e820b..b638a347cba 100644 --- a/src/vs/workbench/contrib/files/browser/fileCommands.ts +++ b/src/vs/workbench/contrib/files/browser/fileCommands.ts @@ -314,7 +314,10 @@ function saveSelectedEditors(accessor: ServicesAccessor, options?: ISaveEditorsO const listService = accessor.get(IListService); const editorGroupsService = accessor.get(IEditorGroupsService); - const saveableEditors = getMultiSelectedEditors(listService, editorGroupsService).filter(({ editor }) => !editor.isReadonly()); + let saveableEditors = getMultiSelectedEditors(listService, editorGroupsService); + if (!options?.saveAs) { + saveableEditors = saveableEditors.filter(({ editor }) => !editor.isReadonly()); // Save: only allow non-readonly editors + } return doSaveEditors(accessor, saveableEditors, options); } @@ -323,7 +326,7 @@ function saveEditorsOfGroups(accessor: ServicesAccessor, groups: ReadonlyArray { - const editors: IEditorIdentifier[] = []; - // Collect all editors in MRU order that are dirty - this.forEachDirtyEditor(({ groupId, editor }) => { - if (!editor.isUntitled() || options?.includeUntitled) { - editors.push({ groupId, editor }); - } - }); + // Save each editor in MRU order + const editors: IEditorIdentifier[] = []; + this.forEachDirtySaveableEditor(!!options?.includeUntitled, ({ groupId, editor }) => editors.push({ groupId, editor })); return this.save(editors, options); } @@ -728,15 +724,15 @@ export class EditorService extends Disposable implements EditorServiceImpl { // Revert each editor in MRU order const reverts: Promise[] = []; - this.forEachDirtyEditor(({ editor }) => reverts.push(editor.revert(options))); + this.forEachDirtySaveableEditor(true /* include untitled */, ({ editor }) => reverts.push(editor.revert(options))); await Promise.all(reverts); } - private forEachDirtyEditor(callback: (editor: IEditorIdentifier) => void): void { + private forEachDirtySaveableEditor(includeUntitled: boolean, callback: (editor: IEditorIdentifier) => void): void { for (const group of this.editorGroupService.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE)) { for (const editor of group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE)) { - if (editor.isDirty()) { + if (editor.isDirty() && !editor.isReadonly() && (!editor.isUntitled() || includeUntitled)) { callback({ groupId: group.id, editor }); } }