Skip to content

Commit 7c526f2

Browse files
author
Benjamin Pasero
committed
files - respect editor.isReadonly() better
1 parent ca0adce commit 7c526f2

3 files changed

Lines changed: 12 additions & 13 deletions

File tree

src/vs/workbench/common/editor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ export abstract class EditorInput extends Disposable implements IEditorInput {
484484
abstract resolve(): Promise<IEditorModel | null>;
485485

486486
isReadonly(): boolean {
487-
return false;
487+
return true;
488488
}
489489

490490
isUntitled(): boolean {

src/vs/workbench/contrib/files/browser/fileCommands.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,10 @@ function saveSelectedEditors(accessor: ServicesAccessor, options?: ISaveEditorsO
314314
const listService = accessor.get(IListService);
315315
const editorGroupsService = accessor.get(IEditorGroupsService);
316316

317-
const saveableEditors = getMultiSelectedEditors(listService, editorGroupsService).filter(({ editor }) => !editor.isReadonly());
317+
let saveableEditors = getMultiSelectedEditors(listService, editorGroupsService);
318+
if (!options?.saveAs) {
319+
saveableEditors = saveableEditors.filter(({ editor }) => !editor.isReadonly()); // Save: only allow non-readonly editors
320+
}
318321

319322
return doSaveEditors(accessor, saveableEditors, options);
320323
}
@@ -323,7 +326,7 @@ function saveEditorsOfGroups(accessor: ServicesAccessor, groups: ReadonlyArray<I
323326
const saveableEditors: IEditorIdentifier[] = [];
324327
for (const group of groups) {
325328
for (const editor of group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE)) {
326-
if (editor.isDirty()) {
329+
if (editor.isDirty() && !editor.isReadonly()) {
327330
saveableEditors.push({ groupId: group.id, editor });
328331
}
329332
}

src/vs/workbench/services/editor/browser/editorService.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -712,14 +712,10 @@ export class EditorService extends Disposable implements EditorServiceImpl {
712712
}
713713

714714
saveAll(options?: ISaveAllEditorsOptions): Promise<boolean> {
715-
const editors: IEditorIdentifier[] = [];
716715

717-
// Collect all editors in MRU order that are dirty
718-
this.forEachDirtyEditor(({ groupId, editor }) => {
719-
if (!editor.isUntitled() || options?.includeUntitled) {
720-
editors.push({ groupId, editor });
721-
}
722-
});
716+
// Save each editor in MRU order
717+
const editors: IEditorIdentifier[] = [];
718+
this.forEachDirtySaveableEditor(!!options?.includeUntitled, ({ groupId, editor }) => editors.push({ groupId, editor }));
723719

724720
return this.save(editors, options);
725721
}
@@ -728,15 +724,15 @@ export class EditorService extends Disposable implements EditorServiceImpl {
728724

729725
// Revert each editor in MRU order
730726
const reverts: Promise<boolean>[] = [];
731-
this.forEachDirtyEditor(({ editor }) => reverts.push(editor.revert(options)));
727+
this.forEachDirtySaveableEditor(true /* include untitled */, ({ editor }) => reverts.push(editor.revert(options)));
732728

733729
await Promise.all(reverts);
734730
}
735731

736-
private forEachDirtyEditor(callback: (editor: IEditorIdentifier) => void): void {
732+
private forEachDirtySaveableEditor(includeUntitled: boolean, callback: (editor: IEditorIdentifier) => void): void {
737733
for (const group of this.editorGroupService.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE)) {
738734
for (const editor of group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE)) {
739-
if (editor.isDirty()) {
735+
if (editor.isDirty() && !editor.isReadonly() && (!editor.isUntitled() || includeUntitled)) {
740736
callback({ groupId: group.id, editor });
741737
}
742738
}

0 commit comments

Comments
 (0)