快捷键调整

This commit is contained in:
fofolee 2022-04-21 10:23:38 +08:00
parent 70321d7df3
commit bb247ee8c8
2 changed files with 27 additions and 11 deletions

View File

@ -221,6 +221,7 @@
:placeholder="true" :placeholder="true"
ref="editor" ref="editor"
@typing="(val) => (quickcommandInfo.cmd = val)" @typing="(val) => (quickcommandInfo.cmd = val)"
@keyStroke="monacoKeyStroke"
:style="{ :style="{
top: languageBarHeight + 'px', top: languageBarHeight + 'px',
left: this.action.type === 'run' ? 0 : this.sideBarWidth + 'px', left: this.action.type === 'run' ? 0 : this.sideBarWidth + 'px',
@ -272,6 +273,7 @@ export default {
resultMaxLength: 10000, resultMaxLength: 10000,
showSidebar: this.action.type !== "run", showSidebar: this.action.type !== "run",
isRunCodePage: this.action.type === "run", isRunCodePage: this.action.type === "run",
listener: null,
}; };
}, },
props: { props: {
@ -279,17 +281,9 @@ export default {
}, },
mounted() { mounted() {
this.init(); this.init();
this.$refs.sidebar?.init();
}, },
beforeUnmount() { beforeUnmount() {
!!this.recording && document.removeEventListener("keyup", this.recording); this.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"
);
}, },
computed: { computed: {
configurationPage() { configurationPage() {
@ -320,6 +314,7 @@ export default {
if (this.quickcommandInfo.tags?.includes("默认") && !utools.isDev()) { if (this.quickcommandInfo.tags?.includes("默认") && !utools.isDev()) {
this.canCommandSave = false; this.canCommandSave = false;
} }
this.$refs.sidebar?.init();
}, },
programChanged(value) { programChanged(value) {
this.setLanguage(value); this.setLanguage(value);
@ -383,6 +378,27 @@ export default {
command.cmdType = this.$refs.sidebar?.cmdType.name; command.cmdType = this.$refs.sidebar?.cmdType.name;
this.$refs.result.runCurrentCommand(command); 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;
}
},
}, },
}; };
</script> </script>

View File

@ -217,7 +217,7 @@ export default {
this.rawEditor.addCommand( this.rawEditor.addCommand(
monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyB, monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyB,
() => { () => {
that.$parent.runCurrentCommand(); that.$emit("keyStroke", "run");
} }
); );
// alt + z // alt + z
@ -229,7 +229,7 @@ export default {
this.rawEditor.addCommand( this.rawEditor.addCommand(
monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS,
() => { () => {
that.$parent.saveCurrentCommand(); that.$emit("keyStroke", "save");
} }
); );
}, },