From 70321d7df3efee5687d09c8d75bd18bb17440d03 Mon Sep 17 00:00:00 2001 From: fofolee Date: Thu, 21 Apr 2022 00:31:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=8C=89=E9=94=AE=E5=BD=95?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/CommandEditor.vue | 79 ++++++++-------------------- src/components/popup/KeyRecorder.vue | 52 ++++++++++++++++++ src/components/popup/QuickAction.vue | 2 +- 3 files changed, 74 insertions(+), 59 deletions(-) create mode 100644 src/components/popup/KeyRecorder.vue diff --git a/src/components/CommandEditor.vue b/src/components/CommandEditor.vue index 284bc22..28a5762 100644 --- a/src/components/CommandEditor.vue +++ b/src/components/CommandEditor.vue @@ -98,20 +98,13 @@ {{ - [ - !!recording ? "停止录制" : "录制按键", - "快捷动作", - "查看文档", - ][index] + ["录制按键", "快捷动作", "查看文档"][index] }} @@ -219,8 +208,11 @@ > - + + + @@ -245,17 +237,24 @@ import MonacoEditor from "components/MonacoEditor"; import CommandSideBar from "components/CommandSideBar"; import CommandRunResult from "components/CommandRunResult"; import QuickAction from "components/popup/QuickAction"; -const Mousetrap = require("mousetrap-record")(require("mousetrap")); +import KeyRecorder from "components/popup/KeyRecorder"; export default { - components: { MonacoEditor, CommandSideBar, CommandRunResult, QuickAction }, + components: { + MonacoEditor, + CommandSideBar, + CommandRunResult, + QuickAction, + KeyRecorder, + }, data() { return { programLanguages: Object.keys(this.$root.programs), sideBarWidth: 250, languageBarHeight: 40, canCommandSave: this.action.type === "code" ? false : true, - isActionsShow: false, + showActions: false, + showRecorder: false, quickcommandInfo: { program: "quickcommand", cmd: "", @@ -273,7 +272,6 @@ export default { resultMaxLength: 10000, showSidebar: this.action.type !== "run", isRunCodePage: this.action.type === "run", - recording: null, }; }, props: { @@ -343,43 +341,8 @@ export default { let highlight = this.$root.programs[language].highlight; this.$refs.editor.setEditorLanguage(highlight ? highlight : language); }, - recordKeys() { - let keys = []; - this.recording = (event) => { - event.preventDefault(); - keys.push( - event.code.includes("Key") ? event.code.slice(-1) : event.key - ); - setTimeout(() => { - this.$refs.editor.repacleEditorSelection( - this.generatedKeyTapCode(this.keyAnalysis(keys.slice(0, 2))) - ); - keys = []; - }, 200); - }; - document.addEventListener("keyup", this.recording); - }, - stopRecord() { - document.removeEventListener("keyup", this.recording); - this.recording = null; - }, - keyAnalysis(keys) { - if (keys.length === 1) return keys; - keys = keys.sort((x, y) => x.length - y.length); - if (keys[1].length === 1) keys.pop(); - return keys; - }, - generatedKeyTapCode(keys) { - return `keyTap("${keys - .join(", ") - .replace("Meta", "command") - .toLowerCase()}")\n`; - }, - showActions() { - this.isActionsShow = true; - }, - addAction(payload) { - this.$refs.editor.repacleEditorSelection(payload); + insertText(text) { + this.$refs.editor.repacleEditorSelection(text); }, // 打开文档 showHelp() { diff --git a/src/components/popup/KeyRecorder.vue b/src/components/popup/KeyRecorder.vue new file mode 100644 index 0000000..3d3f20c --- /dev/null +++ b/src/components/popup/KeyRecorder.vue @@ -0,0 +1,52 @@ + + + diff --git a/src/components/popup/QuickAction.vue b/src/components/popup/QuickAction.vue index 7ca1df5..d9020d5 100644 --- a/src/components/popup/QuickAction.vue +++ b/src/components/popup/QuickAction.vue @@ -81,7 +81,7 @@ const quickActions = [ { value: "quickcommand.sleep", label: "添加延时", - desc: "延迟的毫秒数,不要勾选“加引号”", + desc: "延迟的毫秒数", }, ];