From db1934da588ee2a8f347bd18976d187eb3e20961 Mon Sep 17 00:00:00 2001 From: yy <40423888+yy-wow@users.noreply.github.com> Date: Tue, 18 Feb 2025 05:02:51 -0800 Subject: [PATCH] feat: shortcut key for saving (#951) --- 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 0b545ea3..610835a7 100644 --- a/packages/common/component/MonacoEditor.vue +++ b/packages/common/component/MonacoEditor.vue @@ -40,6 +40,7 @@ :options="editorOptions" language="javascript" @editorDidMount="$emit('editorDidMount', $event)" + @shortcutSave="$emit('shortcutSave', $event)" @change="$emit('change', $event)" > @@ -75,7 +76,7 @@ export default { default: true } }, - emits: ['editorDidMount', 'change', 'fullscreenChange'], + emits: ['editorDidMount', 'change', 'fullscreenChange', 'shortcutSave'], setup(props, { emit }) { const editor = ref(null) const fullscreen = ref(false) diff --git a/packages/common/component/VueMonaco.vue b/packages/common/component/VueMonaco.vue index c2e66133..901028be 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 ca0ad37b..74c219f5 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" >