如何从摩纳哥编辑器的操作列表中隐藏 "Command Palette" 项

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

我一直在到处寻找,摩纳哥文档,github,但是似乎没有关于如何从上下文菜单中隐藏和禁用 "command palette" 命令的示例:

有什么建议吗?

哦,我别无选择,只能侵入 DOM 以删除“命令面板”。

它远非理想,它也没有真正禁用 F1 快捷方式,但这是我现在唯一拥有的东西:

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"
            }
        }
    }
}

另一个解决方案,实际上并不比编辑 dom 好多少。

创建编辑器时,您可以覆盖存储服务。当按下 F1 时,存储服务会查找键 commandPalette.mru.counter。如果在这种情况下抛出错误,命令面板将不会显示。

monaco.editor.create(domElement, options, {
  storageService: {
    get() {},
    remove() {},
    getNumber(key: string) { if(key === 'commandPalette.mru.counter') throw new Error(); return 0; },
    getBoolean(key: string) {},
    store() {},
    onWillSaveState() {},
    onDidChangeStorage() {},
  }