@@ -15,14 +15,15 @@ import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/brows
1515import { EditorAction , ServicesAccessor , registerEditorAction , registerEditorContribution } from 'vs/editor/browser/editorExtensions' ;
1616import { IEditorContribution , ScrollType } from 'vs/editor/common/editorCommon' ;
1717import { EditorContextKeys } from 'vs/editor/common/editorContextKeys' ;
18- import { IMenuService , MenuId } from 'vs/platform/actions/common/actions' ;
18+ import { IMenuService , MenuId , SubmenuItemAction } from 'vs/platform/actions/common/actions' ;
1919import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
2020import { IContextMenuService , IContextViewService } from 'vs/platform/contextview/browser/contextView' ;
2121import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
2222import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry' ;
2323import { ITextModel } from 'vs/editor/common/model' ;
2424import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent' ;
2525import { EditorOption } from 'vs/editor/common/config/editorOptions' ;
26+ import { ContextSubMenu } from 'vs/base/browser/contextmenu' ;
2627
2728export class ContextMenuController implements IEditorContribution {
2829
@@ -128,24 +129,35 @@ export class ContextMenuController implements IEditorContribution {
128129 }
129130
130131 // Find actions available for menu
131- const menuActions = this . _getMenuActions ( this . _editor . getModel ( ) ) ;
132+ const menuActions = this . _getMenuActions ( this . _editor . getModel ( ) , MenuId . EditorContext ) ;
132133
133134 // Show menu if we have actions to show
134135 if ( menuActions . length > 0 ) {
135136 this . _doShowContextMenu ( menuActions , anchor ) ;
136137 }
137138 }
138139
139- private _getMenuActions ( model : ITextModel ) : ReadonlyArray < IAction > {
140+ private _getMenuActions ( model : ITextModel , menuId : MenuId ) : IAction [ ] {
140141 const result : IAction [ ] = [ ] ;
141142
142- let contextMenu = this . _menuService . createMenu ( MenuId . EditorContext , this . _contextKeyService ) ;
143- const groups = contextMenu . getActions ( { arg : model . uri } ) ;
144- contextMenu . dispose ( ) ;
143+ // get menu groups
144+ const menu = this . _menuService . createMenu ( menuId , this . _contextKeyService ) ;
145+ const groups = menu . getActions ( { arg : model . uri } ) ;
146+ menu . dispose ( ) ;
145147
148+ // translate them into other actions
146149 for ( let group of groups ) {
147150 const [ , actions ] = group ;
148- result . push ( ...actions ) ;
151+ for ( const action of actions ) {
152+ if ( action instanceof SubmenuItemAction ) {
153+ const subActions = this . _getMenuActions ( model , action . item . submenu ) ;
154+ if ( subActions . length > 0 ) {
155+ result . push ( new ContextSubMenu ( action . label , subActions ) ) ;
156+ }
157+ } else {
158+ result . push ( action ) ;
159+ }
160+ }
149161 result . push ( new Separator ( ) ) ;
150162 }
151163 result . pop ( ) ; // remove last separator
0 commit comments