From a4551f9e4c5a8fa23b12d11f7f05760d4a7126bd Mon Sep 17 00:00:00 2001 From: sawka Date: Wed, 31 Jul 2024 19:41:16 -0700 Subject: [PATCH] bind Cmd-r,s,e directly with Monaco for codeedit --- frontend/app/view/codeeditor/codeeditor.tsx | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/frontend/app/view/codeeditor/codeeditor.tsx b/frontend/app/view/codeeditor/codeeditor.tsx index 4d2a03e9..60c49a69 100644 --- a/frontend/app/view/codeeditor/codeeditor.tsx +++ b/frontend/app/view/codeeditor/codeeditor.tsx @@ -128,6 +128,27 @@ export function CodeEditor({ } } + function handleEditorOnMount(editor: MonacoTypes.editor.IStandaloneCodeEditor, monaco: Monaco) { + // bind Cmd:e + editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyE, () => { + if (onEdit) { + onEdit(); + } + }); + // bind Cmd:s + editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, () => { + if (onSave) { + onSave(); + } + }); + // bind Cmd:r + editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyR, () => { + if (onCancel) { + onCancel(); + } + }); + } + const editorOpts = defaultEditorOptions(); editorOpts.readOnly = readonly; @@ -140,6 +161,7 @@ export function CodeEditor({ value={text} options={editorOpts} onChange={handleEditorChange} + onMount={handleEditorOnMount} path={filename} language={language} />