mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
save file as: give priority to active editor if triggered from menu
fixes #45414
This commit is contained in:
parent
66a44df0db
commit
3f731d364a
|
@ -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));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue