import { MonacoUtils } from "./monaco-utils" ; import { ITree , ContextMenuEvent } from "./monaco-extra" ; export function getController ( target , getActionsFn ? , resolveMenuHeight ? ) { return class Controller extends MonacoUtils . TreeDefaults . DefaultController { onContextMenu ( tree , file , event ) { tree . setFocus ( file ) ; const anchorOffset = { x : - 10 , y : - 3 } ; const anchor = { x : event . _posx + anchorOffset . x , y : event . _posy + anchorOffset . y } ; const actions = getActionsFn && getActionsFn ( file , event ) ; if ( ! actions || ! actions . length ) { return false ; } target . contextMenuService . showContextMenu ( { getAnchor : ( ) => anchor , getActions : ( ) => monaco . Promise . as ( actions || [ ] ) , getActionItem : ( action ) : any => null , onHide : ( wasCancelled ? ) => { if ( wasCancelled ) { tree . domFocus ( ) ; } } } ) ; super . onContextMenu ( tree , file , event ) ; if ( resolveMenuHeight ) { this . resolveMenuHeight ( event ) ; } return true ; } resolveMenuHeight ( event ) { const menu = document . querySelector ( ".context-view.monaco-menu-container" ) ; const windowPadding = 10 ; menu . style . maxHeight = Math . min ( window . innerHeight - event . _posy - windowPadding , 380 ) + "px" ; } } ; } export function createController ( target , getActionsFn ? , resolveMenuHeight ? ) { const Controller = getController ( target , getActionsFn , resolveMenuHeight ) ; return new Controller ( ) ; }