From 1893fa927198c47c62bd84ac3059026fa0db42ca Mon Sep 17 00:00:00 2001 From: yy-wow Date: Sun, 22 Dec 2024 23:41:04 -0800 Subject: [PATCH] feat: shortcut key for saving --- packages/common/component/MonacoEditor.vue | 3 ++- packages/common/component/VueMonaco.vue | 7 ++++++- packages/plugins/schema/src/Main.vue | 1 + packages/plugins/script/src/Main.vue | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/common/component/MonacoEditor.vue b/packages/common/component/MonacoEditor.vue index 8c6fc85820..86fee58ebb 100644 --- a/packages/common/component/MonacoEditor.vue +++ b/packages/common/component/MonacoEditor.vue @@ -28,6 +28,7 @@ :options="editorOptions" language="javascript" @editorDidMount="$emit('editorDidMount', $event)" + @shortcutSave="$emit('shortcutSave', $event)" > @@ -60,7 +61,7 @@ export default { default: true } }, - emits: ['editorDidMount'], + emits: ['editorDidMount', 'shortcutSave'], setup(props) { const editor = ref(null) const fullscreen = ref(false) diff --git a/packages/common/component/VueMonaco.vue b/packages/common/component/VueMonaco.vue index c2e661330d..901028be5f 100644 --- a/packages/common/component/VueMonaco.vue +++ b/packages/common/component/VueMonaco.vue @@ -43,7 +43,7 @@ export default { default: false } }, - emits: ['change', 'editorWillMount', 'editorDidMount'], + emits: ['change', 'editorWillMount', 'editorDidMount', 'shortcutSave'], setup(props, { emit }) { const vueMonaco = { editor: null, @@ -95,6 +95,11 @@ export default { vueMonaco.editor = monaco.editor.create(monacoRef.value, options) } + vueMonaco.editor.addCommand(monacoEditor.KeyMod.CtrlCmd | monacoEditor.KeyCode.KeyS, () => { + // 快捷键 ctrl + s 或 command + s 保存 + emit('shortcutSave') + }) + const editor2 = getModifiedEditor() editor2.onDidChangeModelContent((event) => { diff --git a/packages/plugins/schema/src/Main.vue b/packages/plugins/schema/src/Main.vue index 5047a535ae..566587d15c 100644 --- a/packages/plugins/schema/src/Main.vue +++ b/packages/plugins/schema/src/Main.vue @@ -26,6 +26,7 @@ :value="state.pageData" :options="options" @change="editorChange" + @shortcutSave="saveSchema" >