@@ -35,13 +35,15 @@ import * as Root from '../../core/root/root.js';
3535import * as VisualLogging from '../visual_logging/visual_logging.js' ;
3636
3737import { ActionRegistry } from './ActionRegistry.js' ;
38+ import type { Key , Modifier } from './KeyboardShortcut.js' ;
3839import { ShortcutRegistry } from './ShortcutRegistry.js' ;
3940import { SoftContextMenu , type SoftContextMenuDescriptor } from './SoftContextMenu.js' ;
4041import { deepElementFromEvent } from './UIUtils.js' ;
4142
4243export class Item {
4344 private readonly typeInternal : string ;
4445 protected readonly label : string | undefined ;
46+ protected accelerator ?: Host . InspectorFrontendHostAPI . AcceleratorDescriptor ;
4547 protected readonly previewFeature : boolean ;
4648 protected disabled : boolean | undefined ;
4749 private readonly checked : boolean | undefined ;
@@ -54,11 +56,13 @@ export class Item {
5456
5557 constructor (
5658 contextMenu : ContextMenu | null , type : 'checkbox' | 'item' | 'separator' | 'subMenu' , label ?: string ,
57- isPreviewFeature ?: boolean , disabled ?: boolean , checked ?: boolean , tooltip ?: Platform . UIString . LocalizedString ,
59+ isPreviewFeature ?: boolean , disabled ?: boolean , checked ?: boolean ,
60+ accelerator ?: Host . InspectorFrontendHostAPI . AcceleratorDescriptor , tooltip ?: Platform . UIString . LocalizedString ,
5861 jslogContext ?: string ) {
5962 this . typeInternal = type ;
6063 this . label = label ;
6164 this . previewFeature = Boolean ( isPreviewFeature ) ;
65+ this . accelerator = accelerator ;
6266 this . disabled = disabled ;
6367 this . checked = checked ;
6468 this . contextMenu = contextMenu ;
@@ -113,6 +117,9 @@ export class Item {
113117 if ( this . shortcut ) {
114118 result . shortcut = this . shortcut ;
115119 }
120+ if ( this . accelerator ) {
121+ result . accelerator = this . accelerator ;
122+ }
116123 return result ;
117124 }
118125 case 'separator' : {
@@ -145,6 +152,11 @@ export class Item {
145152 throw new Error ( 'Invalid item type:' + this . typeInternal ) ;
146153 }
147154
155+ setAccelerator ( key : Key , modifiers : Modifier [ ] ) : void {
156+ const modifierSum = modifiers . reduce ( ( result , modifier ) => result + modifier . value , 0 ) ;
157+ this . accelerator = { keyCode : key . code , modifiers : modifierSum } ;
158+ }
159+
148160 setShortcut ( shortcut : string ) : void {
149161 this . shortcut = shortcut ;
150162 }
@@ -159,15 +171,16 @@ export class Section {
159171 }
160172
161173 appendItem ( label : string , handler : ( ) => void , options ?: {
174+ accelerator ?: Host . InspectorFrontendHostAPI . AcceleratorDescriptor ,
162175 isPreviewFeature ?: boolean ,
163176 disabled ?: boolean ,
164177 additionalElement ?: Element ,
165178 tooltip ?: Platform . UIString . LocalizedString ,
166179 jslogContext ?: string ,
167180 } ) : Item {
168181 const item = new Item (
169- this . contextMenu , 'item' , label , options ?. isPreviewFeature , options ?. disabled , undefined , options ?. tooltip ,
170- options ?. jslogContext ) ;
182+ this . contextMenu , 'item' , label , options ?. isPreviewFeature , options ?. disabled , undefined , options ?. accelerator ,
183+ options ?. tooltip , options ?. jslogContext ) ;
171184 if ( options ?. additionalElement ) {
172185 item . customElement = options ?. additionalElement ;
173186 }
@@ -179,8 +192,8 @@ export class Section {
179192 }
180193
181194 appendCustomItem ( element : Element , jslogContext ?: string ) : Item {
182- const item =
183- new Item ( this . contextMenu , 'item' , undefined , undefined , undefined , undefined , undefined , jslogContext ) ;
195+ const item = new Item (
196+ this . contextMenu , 'item' , undefined , undefined , undefined , undefined , undefined , undefined , jslogContext ) ;
184197 item . customElement = element ;
185198 this . items . push ( item ) ;
186199 return item ;
@@ -225,8 +238,8 @@ export class Section {
225238 jslogContext ?: string ,
226239 } ) : Item {
227240 const item = new Item (
228- this . contextMenu , 'checkbox' , label , undefined , options ?. disabled , options ?. checked , options ?. tooltip ,
229- options ?. jslogContext ) ;
241+ this . contextMenu , 'checkbox' , label , undefined , options ?. disabled , options ?. checked , undefined ,
242+ options ?. tooltip , options ?. jslogContext ) ;
230243 this . items . push ( item ) ;
231244 if ( this . contextMenu ) {
232245 this . contextMenu . setHandler ( item . id ( ) , handler ) ;
@@ -243,7 +256,7 @@ export class SubMenu extends Item {
243256 private readonly sectionList : Section [ ] ;
244257
245258 constructor ( contextMenu : ContextMenu | null , label ?: string , disabled ?: boolean , jslogContext ?: string ) {
246- super ( contextMenu , 'subMenu' , label , undefined , disabled , undefined , undefined , jslogContext ) ;
259+ super ( contextMenu , 'subMenu' , label , undefined , disabled , undefined , undefined , undefined , jslogContext ) ;
247260 this . sections = new Map ( ) ;
248261 this . sectionList = [ ] ;
249262 }
@@ -317,6 +330,7 @@ export class SubMenu extends Item {
317330 const result : Host . InspectorFrontendHostAPI . ContextMenuDescriptor | SoftContextMenuDescriptor = {
318331 type : 'subMenu' ,
319332 label : this . label ,
333+ accelerator : this . accelerator ,
320334 isExperimentalFeature : this . previewFeature ,
321335 enabled : ! this . disabled ,
322336 subItems : [ ] ,
0 commit comments