Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Monaco context menu?

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?

like image 972
bcherny Avatar asked Dec 07 '22 17:12

bcherny


2 Answers

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 });
like image 179
webdeb Avatar answered Dec 11 '22 09:12

webdeb


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;
});
like image 33
Vikram kumar Chhajer Avatar answered Dec 11 '22 10:12

Vikram kumar Chhajer