Skip to content
Advertisement

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

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:

command palette

Any advice?

Advertisement

Answer

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"
            }
        }
    }
}
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement