How to disable Monaco context menu?

懵懂的女人 提交于 2019-12-10 18:55:11

问题


I am using monaco-editor, and am trying to add a custom handler for Command+Enter. But when I press the command key, the Monaco context menu shows up. Is it possible to disable the context menu, or to rebind it to another key?


回答1:


Sure, you can disable it, just set contextmenu to false ;)

monaco.editor.create(document.getElementById("container"), {
  value: "function hello() {\n\talert('Hello world!');\n}",
  language: "javascript",
  // ---------
  contextmenu: false, // or set another keyCode here
});



回答2:


There are two ways to disable contextMenu. One which you can define while creating editor. Which is similar to answer given by webdeb. But if on runtime you want to enable/disable contextMenu, you can use following function.

monaco.editor.updateOptions({
   contextmenu: false;
});



回答3:


The correct code is:

monaco.editor.updateOptions({ contextmenu: false });

The semicolon after the false throws an error.



来源:https://stackoverflow.com/questions/44750658/how-to-disable-monaco-context-menu

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