提交 3f731d36 编写于 作者: I isidor

save file as: give priority to active editor if triggered from menu

fixes #45414
上级 66a44df0
......@@ -16,16 +16,12 @@ import { IFileStat } from 'vs/platform/files/common/files';
// Commands can get exeucted from a command pallete, from a context menu or from some list using a keybinding
// To cover all these cases we need to properly compute the resource on which the command is being executed
export function getResourceForCommand(resource: URI | object | { from: string }, listService: IListService, editorService: IWorkbenchEditorService): URI {
export function getResourceForCommand(resource: URI | object, listService: IListService, editorService: IWorkbenchEditorService): URI {
if (URI.isUri(resource)) {
return resource;
}
let list = listService.lastFocusedList;
if (resource && 'from' in resource && resource.from === 'menu') {
// Ignore list if the command is triggered from the main menu
list = undefined;
}
let list = listService.lastFocusedList;
if (list && list.isDOMFocused()) {
const focus = list.getFocus();
if (focus instanceof FileStat) {
......@@ -38,7 +34,7 @@ export function getResourceForCommand(resource: URI | object | { from: string },
return toResource(editorService.getActiveEditorInput(), { supportSideBySide: true });
}
export function getMultiSelectedResources(resource: URI | object | { from: string }, listService: IListService, editorService: IWorkbenchEditorService): URI[] {
export function getMultiSelectedResources(resource: URI | object, listService: IListService, editorService: IWorkbenchEditorService): URI[] {
const list = listService.lastFocusedList;
if (list && list.isDOMFocused()) {
// Explorer
......
......@@ -486,9 +486,16 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: undefined,
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_S,
handler: (accessor, resource: URI | object) => {
handler: (accessor, resourceOrObject: URI | object | { from: string }) => {
const editorService = accessor.get(IWorkbenchEditorService);
return save(getResourceForCommand(resource, accessor.get(IListService), editorService), true, editorService, accessor.get(IFileService), accessor.get(IUntitledEditorService), accessor.get(ITextFileService), accessor.get(IEditorGroupService));
let resource: URI = undefined;
if (resourceOrObject && 'from' in resourceOrObject && resourceOrObject.from === 'menu') {
resource = toResource(editorService.getActiveEditorInput());
} else {
resource = getResourceForCommand(resourceOrObject, accessor.get(IListService), editorService);
}
return save(resource, true, editorService, accessor.get(IFileService), accessor.get(IUntitledEditorService), accessor.get(ITextFileService), accessor.get(IEditorGroupService));
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册