From a78363abd0fcbca5f8e1d4e7543cafa8500e9952 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Fri, 22 Nov 2019 12:33:22 +0100 Subject: [PATCH] fix missing entries from global go menu --- src/vs/editor/browser/editorExtensions.ts | 55 ++++++++----------- .../editor/contrib/gotoSymbol/goToCommands.ts | 15 +++-- 2 files changed, 32 insertions(+), 38 deletions(-) diff --git a/src/vs/editor/browser/editorExtensions.ts b/src/vs/editor/browser/editorExtensions.ts index 408881eb438..18bd6370f27 100644 --- a/src/vs/editor/browser/editorExtensions.ts +++ b/src/vs/editor/browser/editorExtensions.ts @@ -44,8 +44,8 @@ export interface ICommandKeybindingsOptions extends IKeybindings { } export interface ICommandMenuOptions { menuId: MenuId; - group?: string; - order?: number; + group: string; + order: number; when?: ContextKeyExpr; title: string; } @@ -194,53 +194,42 @@ export interface IEditorActionContextMenuOptions { group: string; order: number; when?: ContextKeyExpr; + menuId?: MenuId; } -export interface IActionOptions { - id: string; +export interface IActionOptions extends ICommandOptions { label: string; alias: string; - description?: ICommandHandlerDescription; - precondition: ContextKeyExpr | undefined; - kbOpts?: ICommandKeybindingsOptions; - contextMenuOpts?: IEditorActionContextMenuOptions; - menuOpts?: Partial | Partial; + contextMenuOpts?: IEditorActionContextMenuOptions | IEditorActionContextMenuOptions[]; } export abstract class EditorAction extends EditorCommand { private static convertOptions(opts: IActionOptions): ICommandOptions { - function patch(menu: Partial): ICommandMenuOptions { - if (!menu.title) { - menu.title = opts.label; - } - if (!menu.menuId) { - menu.menuId = MenuId.EditorContext; - } - if (!menu.when) { - menu.when = opts.precondition; - } - return menu; - } - let menuOpts: ICommandMenuOptions[]; if (Array.isArray(opts.menuOpts)) { - menuOpts = opts.menuOpts.map(m => patch(m!)); + menuOpts = opts.menuOpts; } else if (opts.menuOpts) { - menuOpts = [patch(opts.menuOpts)]; + menuOpts = [opts.menuOpts]; } else { menuOpts = []; } - if (opts.contextMenuOpts) { - const contextMenuItem = { - title: opts.label, - when: ContextKeyExpr.and(opts.precondition, opts.contextMenuOpts.when), - menuId: MenuId.EditorContext, - group: opts.contextMenuOpts.group, - order: opts.contextMenuOpts.order - }; - menuOpts.push(contextMenuItem); + function withDefaults(item: Partial): ICommandMenuOptions { + if (!item.menuId) { + item.menuId = MenuId.EditorContext; + } + if (!item.title) { + item.title = opts.label; + } + item.when = ContextKeyExpr.and(opts.precondition, item.when); + return item; + } + + if (Array.isArray(opts.contextMenuOpts)) { + menuOpts.push(...opts.contextMenuOpts.map(withDefaults)); + } else if (opts.contextMenuOpts) { + menuOpts.push(withDefaults(opts.contextMenuOpts)); } opts.menuOpts = menuOpts; diff --git a/src/vs/editor/contrib/gotoSymbol/goToCommands.ts b/src/vs/editor/contrib/gotoSymbol/goToCommands.ts index f2d7748031a..86f229ecc2f 100644 --- a/src/vs/editor/contrib/gotoSymbol/goToCommands.ts +++ b/src/vs/editor/contrib/gotoSymbol/goToCommands.ts @@ -309,8 +309,9 @@ registerEditorAction(class PeekDefinitionAction extends DefinitionAction { linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.F10 }, weight: KeybindingWeight.EditorContrib }, - menuOpts: { + contextMenuOpts: { menuId: MenuId.EditorContextPeek, + group: 'peek', order: 2 } }); @@ -395,8 +396,9 @@ registerEditorAction(class PeekDeclarationAction extends DeclarationAction { PeekContext.notInPeekEditor, EditorContextKeys.isInEmbeddedEditor.toNegated() ), - menuOpts: { + contextMenuOpts: { menuId: MenuId.EditorContextPeek, + group: 'peek', order: 3 } }); @@ -481,8 +483,9 @@ registerEditorAction(class PeekTypeDefinitionAction extends TypeDefinitionAction PeekContext.notInPeekEditor, EditorContextKeys.isInEmbeddedEditor.toNegated() ), - menuOpts: { + contextMenuOpts: { menuId: MenuId.EditorContextPeek, + group: 'peek', order: 4 } }); @@ -572,8 +575,9 @@ registerEditorAction(class PeekImplementationAction extends ImplementationAction primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.F12, weight: KeybindingWeight.EditorContrib }, - menuOpts: { + contextMenuOpts: { menuId: MenuId.EditorContextPeek, + group: 'peek', order: 5 } }); @@ -656,8 +660,9 @@ registerEditorAction(class PeekReferencesAction extends ReferencesAction { PeekContext.notInPeekEditor, EditorContextKeys.isInEmbeddedEditor.toNegated() ), - menuOpts: { + contextMenuOpts: { menuId: MenuId.EditorContextPeek, + group: 'peek', order: 6 } }); -- GitLab