1- /** @typedef {{label:string,icon?:string,action:()=>any} } ContextMenuEntry */
1+ /** @typedef {{label:()=>Promise< string> ,icon?:string,action:()=>any} } ContextMenuEntry */
22/**
33@typedef {{
44 oncontextmenu: (this: HTMLElement, ev: MouseEvent) => any
@@ -57,7 +57,7 @@ function set_context_menu(/** @type {HTMLElement} */ el, /** @type {(ev: MouseEv
5757 let wrapper_el = null
5858
5959 // The element(s) created by this is quite similar to the template of <git-action-button>
60- function build_context_menu ( /** @type {MouseEvent } */ event ) {
60+ async function build_context_menu ( /** @type {MouseEvent } */ event ) {
6161 let entries = entries_provider ( event )
6262 if ( ! entries || wrapper_el )
6363 return
@@ -66,7 +66,7 @@ function set_context_menu(/** @type {HTMLElement} */ el, /** @type {(ev: MouseEv
6666 wrapper_el . classList . add ( 'context-menu-wrapper' )
6767 wrapper_el . style . setProperty ( 'left' , event . clientX + 'px' )
6868 wrapper_el . style . setProperty ( 'top' , event . clientY + 'px' )
69- entries . forEach ( ( entry ) => {
69+ for ( let entry of entries ) {
7070 let entry_el = document . createElement ( 'li' )
7171 entry_el . setAttribute ( 'role' , 'button' )
7272 entry_el . setAttribute ( 'tabindex' , '-1' )
@@ -75,15 +75,15 @@ function set_context_menu(/** @type {HTMLElement} */ el, /** @type {(ev: MouseEv
7575 if ( entry . icon )
7676 icon_el . classList . add ( 'codicon' , `codicon-${ entry . icon } ` )
7777 let label_el = document . createElement ( 'span' )
78- label_el . textContent = entry . label
78+ label_el . textContent = await entry . label ( )
7979 entry_el . appendChild ( icon_el )
8080 entry_el . appendChild ( label_el )
8181 entry_el . onfocus = ( ) => {
8282 entry . action ( )
8383 remove_all_context_menus ( )
8484 }
8585 wrapper_el ?. appendChild ( entry_el )
86- } )
86+ }
8787 document . body . appendChild ( wrapper_el )
8888 }
8989
0 commit comments