最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to disable Monaco context menu? - Stack Overflow

programmeradmin5浏览0评论

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

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

Share Improve this question asked Jun 25, 2017 at 21:09 bchernybcherny 3,1722 gold badges28 silver badges36 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 14

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
});

OR, (thanks to @razor8088)

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

The correct code is:

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

The semicolon after the false throws an error.

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;
});
发布评论

评论列表(0)

  1. 暂无评论