Skip to content

Commit 44e755b

Browse files
author
Benjamin Pasero
committed
custom editors - support simple save()
1 parent da112cd commit 44e755b

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,30 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
496496
weight: KeybindingWeight.WorkbenchContrib,
497497
primary: KeyMod.CtrlCmd | KeyCode.KEY_S,
498498
id: SAVE_FILE_COMMAND_ID,
499-
handler: (accessor, resource: URI | object) => {
499+
handler: async (accessor, resource: URI | object) => {
500+
const listService = accessor.get(IListService);
501+
const editorGroupsService = accessor.get(IEditorGroupsService);
502+
const notificationService = accessor.get(INotificationService);
503+
504+
const editors = getMultiSelectedEditors(listService, editorGroupsService);
505+
if (editors.length && !editors.some(({ editor }) => editor.getResource()?.scheme === Schemas.untitled)) {
506+
try {
507+
await Promise.all(editors.map(async ({ groupId, editor }) => {
508+
509+
// Use save as a hint to pin the editor
510+
editorGroupsService.getGroup(groupId)?.pinEditor(editor);
511+
512+
return editor.save({ force: true });
513+
}));
514+
} catch (error) {
515+
notificationService.error(nls.localize('genericRevertResourcesError', "Failed to revert '{0}': {1}", editors.map(({ editor }) => editor.getName()).join(', '), toErrorMessage(error, false)));
516+
}
517+
518+
return;
519+
}
520+
500521
const editorService = accessor.get(IEditorService);
501-
const resources = getMultiSelectedResources(resource, accessor.get(IListService), editorService);
522+
const resources = getMultiSelectedResources(resource, listService, editorService);
502523

503524
if (resources.length === 1) {
504525
// If only one resource is selected explictly call save since the behavior is a bit different than save all #41841

0 commit comments

Comments
 (0)