Reputation: 141
I am trying to override Monaco Editor suggestions with my own only when pressing Ctrl-Space. So I decided to begin with:
editor.addCommand(monaco.KeyMod.chord(monaco.KeyCode.Ctrl, monaco.KeyCode.Space), () => console.log("hello world"));
with an intention to replace console.log...
with anything else in the future. But the editor doesn't react and gives me a full list of suggestions instead.
Can anybody give a hint how to override this default behaviour?
Upvotes: 5
Views: 3380
Reputation: 141
Found an answer here https://github.com/microsoft/monaco-editor/issues/1901#issuecomment-609018281 , the answer is I am on MacOS and in this case we need to use monaco.KeyMod.WinCtrl instead of monaco.KeyCode.Ctrl and no need of chords, the full code is:
const editor = monaco.editor.create(document.getElementById("container"), {
value: "function hello() {alert('Hello world!');}",
language: "javascript"
});
editor.addCommand(monaco.KeyMod.WinCtrl | monaco.KeyCode.Space, () => console.log("hello world"))
Upvotes: 6