With Monaco Editor, you can provide custom commands that handle keyboard combinations. For example, the format of the Open command may look as follows:
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_O, () => {
// do something
});
Note that the same command works as Cmd + O on macOS and is Ctrl + O on other systems, such as Windows and Linux. Apply this logic throughout.
Let's create two stubs for the Open and Save functions, which will be handled by the Ctrl + O/Cmd + O and Ctrl + S/Cmd + S commands, respectively:
- In the Editor.js file, update the editorDidMount handler so that it looks as follows:
const editorDidMount = (editor, monaco) => {
console.log('editorDidMount', editor, monaco);
editor.focus();
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_O, () => {
console.log(&apos...