diff --git a/src/components/CommandEditor.vue b/src/components/CommandEditor.vue index 28a5762..8231ad5 100644 --- a/src/components/CommandEditor.vue +++ b/src/components/CommandEditor.vue @@ -221,6 +221,7 @@ :placeholder="true" ref="editor" @typing="(val) => (quickcommandInfo.cmd = val)" + @keyStroke="monacoKeyStroke" :style="{ top: languageBarHeight + 'px', left: this.action.type === 'run' ? 0 : this.sideBarWidth + 'px', @@ -272,6 +273,7 @@ export default { resultMaxLength: 10000, showSidebar: this.action.type !== "run", isRunCodePage: this.action.type === "run", + listener: null, }; }, props: { @@ -279,17 +281,9 @@ export default { }, mounted() { this.init(); - this.$refs.sidebar?.init(); }, beforeUnmount() { - !!this.recording && document.removeEventListener("keyup", this.recording); - if (this.action.type !== "run") return; - let command = _.cloneDeep(this.quickcommandInfo); - command.cursorPosition = this.$refs.editor.getCursorPosition(); - this.$root.utools.putDB( - command, - this.$root.utools.DBPRE.CFG + "codeHistory" - ); + this.saveCodeHistory(); }, computed: { configurationPage() { @@ -320,6 +314,7 @@ export default { if (this.quickcommandInfo.tags?.includes("默认") && !utools.isDev()) { this.canCommandSave = false; } + this.$refs.sidebar?.init(); }, programChanged(value) { this.setLanguage(value); @@ -383,6 +378,27 @@ export default { command.cmdType = this.$refs.sidebar?.cmdType.name; this.$refs.result.runCurrentCommand(command); }, + saveCodeHistory() { + if (this.action.type !== "run") return; + let command = _.cloneDeep(this.quickcommandInfo); + command.cursorPosition = this.$refs.editor.getCursorPosition(); + this.$root.utools.putDB( + command, + this.$root.utools.DBPRE.CFG + "codeHistory" + ); + }, + monacoKeyStroke(event) { + switch (event) { + case "run": + this.runCurrentCommand(); + break; + case "save": + this.saveCurrentCommand(); + break; + default: + break; + } + }, }, }; diff --git a/src/components/MonacoEditor.vue b/src/components/MonacoEditor.vue index b1020b2..2fe47e6 100644 --- a/src/components/MonacoEditor.vue +++ b/src/components/MonacoEditor.vue @@ -217,7 +217,7 @@ export default { this.rawEditor.addCommand( monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyB, () => { - that.$parent.runCurrentCommand(); + that.$emit("keyStroke", "run"); } ); // alt + z 换行 @@ -229,7 +229,7 @@ export default { this.rawEditor.addCommand( monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, () => { - that.$parent.saveCurrentCommand(); + that.$emit("keyStroke", "save"); } ); },