问题
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