How to disable the context menu of Monaco?

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 appears. Is it possible to disable the context menu or reinstall it to a different key?

+3


source to share


3 answers


You can of course disable it, just set it 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
});

      

+5


source


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



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

      

+1


source


Correct code:

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

      

Semicolon after false will throw an error.

0


source







All Articles