How to hide the “Command Palette” item from the list of actions in Monaco Editor

本小妞迷上赌 提交于 2021-01-05 04:34:48

问题


I have been looking everywhere, Monaco docs, github, SO but there seems to be no examples as to how to hide and disable the "command palette" command from the context menu:

Any advice?


回答1:


Oh well, I had no choice but to hack my way into the DOM in order to remove the "Command Palette".

It's very far from ideal and it also doesn't really disable the F1 shortcut but it's only thing I have for now:

private onContextMenu() {
    const menuItems = document.querySelector(".monaco-menu .actions-container");
    if (menuItems && menuItems.childNodes && menuItems.childNodes.length > 0) {
        for (let i = 0; i < menuItems.childNodes.length; i++) {
            const menuItem = menuItems.childNodes[i];
            if (menuItem.innerText.indexOf("Command Palette") !== -1) {
                // remove "Command Pallete" item and it's separator from the menu
                menuItems.removeChild(menuItem); // the "Command Palette" item
                menuItems.removeChild(menuItems.childNodes[i - 1]); // the separator item before "Command Palette"
            }
        }
    }
}


来源:https://stackoverflow.com/questions/52597274/how-to-hide-the-command-palette-item-from-the-list-of-actions-in-monaco-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!