From 261aafaccea2b4fa33b82392795e31f7f3222899 Mon Sep 17 00:00:00 2001 From: fofolee Date: Tue, 12 Apr 2022 22:00:21 +0800 Subject: [PATCH] =?UTF-8?q?monoca=20=E6=B7=BB=E5=8A=A0=E5=BF=AB=E6=8D=B7?= =?UTF-8?q?=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/CommandEditor.vue | 18 +++--------------- src/components/MonocaEditor.vue | 28 +++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/components/CommandEditor.vue b/src/components/CommandEditor.vue index 4e88183..d4fa441 100644 --- a/src/components/CommandEditor.vue +++ b/src/components/CommandEditor.vue @@ -125,8 +125,7 @@ icon="play_arrow" label="运行" @click="runCurrentCommand()" - >{{ commandString }}+b + > {{ commandString }}+s + > @@ -186,7 +184,6 @@ export default { resultMaxLength: 10000, showSidebar: this.action.type !== "run", isRunCodePage: this.action.type === "run", - commandString: this.$q.platform.is.mac ? "⌘" : "ctrl", }; }, props: { @@ -213,7 +210,6 @@ export default { methods: { init() { window.commandEditor = this; - this.bindKeys(); let quickCommandInfo = this.action.type === "run" ? this.$utools.getDB(this.$utools.DBPRE.CFG + "preferences") @@ -230,14 +226,6 @@ export default { if (this.action.type === "run") this.$profile.codeHistory = this.quickcommandInfo; }, - // 绑定快捷键 - bindKeys() { - let that = this; - // ctrl+b 运行 - this.$refs.editor.addEditorCommand(2048 | 32, function () { - that.runCurrentCommand(); - }); - }, programChanged(value) { this.setLanguage(value); this.$refs.sidebar?.setIcon(value); @@ -339,7 +327,7 @@ export default { }, // 保存 saveCurrentCommand() { - let updatedData = this.$refs.sidebar.SaveMenuData(); + let updatedData = this.$refs.sidebar?.SaveMenuData(); if (!updatedData) return; Object.assign(this.quickcommandInfo, _.cloneDeep(updatedData)); let newQuickcommandInfo = _.cloneDeep(this.quickcommandInfo); diff --git a/src/components/MonocaEditor.vue b/src/components/MonocaEditor.vue index 1e8e014..70b5e48 100644 --- a/src/components/MonocaEditor.vue +++ b/src/components/MonocaEditor.vue @@ -21,6 +21,8 @@ export default { data() { return { editor: null, + wordWrap: "off", + commandString: this.$q.platform.is.mac ? "⌘" : "ctrl", }; }, mounted() { @@ -54,6 +56,7 @@ export default { this.registerLanguage(); this.setEditorTheme(); this.listenEditroValue(); + this.bindKeys(); }, loadTypes() { monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({ @@ -154,9 +157,6 @@ export default { setEditorLanguage(language) { monaco.editor.setModelLanguage(this.rawEditor.getModel(), language); }, - addEditorCommand(key, callback) { - this.rawEditor.addCommand(key, callback); - }, repacleEditorSelection(text) { var selection = this.rawEditor.getSelection(); var range = new monaco.Range( @@ -182,6 +182,28 @@ export default { this.$parent.quickcommandInfo.cmd = this.getEditorValue(); }); }, + bindKeys() { + let that = this; + // ctrl + b 运行 + this.rawEditor.addCommand( + monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyB, + () => { + that.$parent.runCurrentCommand(); + } + ); + // alt + z 换行 + this.rawEditor.addCommand(monaco.KeyMod.Alt | monaco.KeyCode.KeyZ, () => { + that.wordWrap = that.wordWrap === "off" ? "on" : "off"; + that.rawEditor.updateOptions({ wordWrap: that.wordWrap }); + }); + // ctrl + s 保存 + this.rawEditor.addCommand( + monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, + () => { + that.$parent.saveCurrentCommand(); + } + ); + }, }, };