From 25b89babacffe4c526dac71ba7d3a64036b8e693 Mon Sep 17 00:00:00 2001 From: Tobias Skarhed <1438972+tskarhed@users.noreply.github.com> Date: Thu, 25 May 2023 10:49:23 +0200 Subject: [PATCH] CodeEditor: Save with Ctrl+S via onKeyDown instead of addCommand (#68955) Change addCommand to onKeyDown --- packages/grafana-ui/src/components/Monaco/CodeEditor.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/grafana-ui/src/components/Monaco/CodeEditor.tsx b/packages/grafana-ui/src/components/Monaco/CodeEditor.tsx index ef5819b74c7..3efcfba0782 100644 --- a/packages/grafana-ui/src/components/Monaco/CodeEditor.tsx +++ b/packages/grafana-ui/src/components/Monaco/CodeEditor.tsx @@ -99,7 +99,14 @@ class UnthemedCodeEditor extends PureComponent { this.getEditorValue = () => editor.getValue(); - editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, this.onSave); + // Save when pressing Ctrl+S or Cmd+S + editor.onKeyDown((e: monacoType.IKeyboardEvent) => { + if (e.keyCode === monaco.KeyCode.KeyS && (e.ctrlKey || e.metaKey)) { + e.preventDefault(); + this.onSave(); + } + }); + const languagePromise = this.loadCustomLanguage(); if (onEditorDidMount) {