From d659fdcc886deaf47edfffe04a98652518583165 Mon Sep 17 00:00:00 2001 From: fofolee Date: Wed, 13 Apr 2022 16:49:47 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=80=E5=87=BA=E6=97=B6=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E5=85=89=E6=A0=87=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 20 +++++++++++++++----- src/components/CommandEditor.vue | 8 +++----- src/components/CommandRunResult.vue | 3 --- src/components/CommandSideBar.vue | 3 --- src/components/ConfigurationMenu.vue | 3 --- src/components/MonacoEditor.vue | 7 +++++++ src/components/quickcommandUI/SelectList.vue | 1 - src/pages/CommandPage.vue | 1 - src/pages/ConfigurationPage.vue | 2 +- src/pages/RunCodePage.vue | 2 +- 10 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/App.vue b/src/App.vue index 4ae5f70..1f4996a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -21,6 +21,7 @@ export default defineComponent({ }, methods: { init() { + window.root = this; window.utools = window.getuToolsLite(); // 版本检测 const requiredVersion = "2.6.1"; @@ -44,17 +45,26 @@ export default defineComponent({ }); // 退出插件 utools.onPluginOut(() => { + // 保存偏好 + this.saveProfile(); // 切到空路由 this.$router.push("loading"); // 清空临时数据 window.temporaryStoreSoldOut(); - // 保存偏好 - this.$utools.putDB( - _.cloneDeep(this.$profile), - this.$utools.DBPRE.CFG + "preferences" - ); }); }, + saveProfile() { + let commandEditor = this.$refs.view.$refs.commandEditor; + if (commandEditor && commandEditor.action.type !== "edit") { + let command = _.cloneDeep(commandEditor.quickcommandInfo); + command.cursorPosition = commandEditor.$refs.editor.getCursorPosition(); + this.$profile.codeHistory[commandEditor.action.type] = command; + } + this.$utools.putDB( + _.cloneDeep(this.$profile), + this.$utools.DBPRE.CFG + "preferences" + ); + }, }, }); diff --git a/src/components/CommandEditor.vue b/src/components/CommandEditor.vue index 3086e2b..f731d31 100644 --- a/src/components/CommandEditor.vue +++ b/src/components/CommandEditor.vue @@ -209,22 +209,20 @@ export default { created() {}, methods: { init() { - window.commandEditor = this; let quickCommandInfo = - this.action.type === "run" + this.action.type !== "edit" ? this.$utools.getDB(this.$utools.DBPRE.CFG + "preferences") - ?.codeHistory + ?.codeHistory[this.action.type] : this.action.data; _.merge(this.quickcommandInfo, quickCommandInfo); // monaco 相关 this.$refs.editor.setEditorValue(this.quickcommandInfo.cmd); this.setLanguage(this.quickcommandInfo.program); + this.$refs.editor.setCursorPosition(this.quickcommandInfo.cursorPosition) // 默认命令不可编辑 if (this.quickcommandInfo.tags?.includes("默认") && !utools.isDev()) { this.canCommandSave = false; } - if (this.action.type === "run") - this.$profile.codeHistory = this.quickcommandInfo; }, programChanged(value) { this.setLanguage(value); diff --git a/src/components/CommandRunResult.vue b/src/components/CommandRunResult.vue index 718450b..6ef4dc1 100644 --- a/src/components/CommandRunResult.vue +++ b/src/components/CommandRunResult.vue @@ -67,9 +67,6 @@ export default { */ action: Object, }, - mounted() { - window.runResult = this; - }, computed: { fromUtools() { return this.action.type === "input"; diff --git a/src/components/CommandSideBar.vue b/src/components/CommandSideBar.vue index d3e8a97..7bf1c47 100644 --- a/src/components/CommandSideBar.vue +++ b/src/components/CommandSideBar.vue @@ -275,9 +275,6 @@ export default { quickcommandInfo: Object, canCommandSave: Boolean, }, - mounted() { - window.CommandSideBar = this; - }, computed: { specialVarsOptions() { let x = Object.values(specialVars).filter( diff --git a/src/components/ConfigurationMenu.vue b/src/components/ConfigurationMenu.vue index df75527..b5942ca 100644 --- a/src/components/ConfigurationMenu.vue +++ b/src/components/ConfigurationMenu.vue @@ -213,9 +213,6 @@ export default { return this.configurationPage.activatedQuickCommandFeatureCodes.length; }, }, - mounted() { - window.configurationMenu = this; - }, props: { isTagStared: Boolean, currentTag: String, diff --git a/src/components/MonacoEditor.vue b/src/components/MonacoEditor.vue index c02c60e..8a46ce1 100644 --- a/src/components/MonacoEditor.vue +++ b/src/components/MonacoEditor.vue @@ -176,6 +176,13 @@ export default { setEditorLanguage(language) { monaco.editor.setModelLanguage(this.rawEditor.getModel(), language); }, + getCursorPosition() { + return this.rawEditor.getPosition(); + }, + setCursorPosition(pos) { + if (!pos) return; + this.rawEditor.setPosition(pos); + }, repacleEditorSelection(text) { var selection = this.rawEditor.getSelection(); var range = new monaco.Range( diff --git a/src/components/quickcommandUI/SelectList.vue b/src/components/quickcommandUI/SelectList.vue index 3967ed0..346c864 100644 --- a/src/components/quickcommandUI/SelectList.vue +++ b/src/components/quickcommandUI/SelectList.vue @@ -76,7 +76,6 @@ export default { }; }, mounted() { - window.SelectList = this; window.temporaryStore.updateSelectList = (opt, id) => { if (typeof id === "undefined") this.items.push(opt); else this.items[id] = opt; diff --git a/src/pages/CommandPage.vue b/src/pages/CommandPage.vue index d7c2063..d70cb72 100644 --- a/src/pages/CommandPage.vue +++ b/src/pages/CommandPage.vue @@ -19,7 +19,6 @@ export default { }; }, mounted() { - window.commandPage = this; this.runCurrentCommand(); }, computed: { diff --git a/src/pages/ConfigurationPage.vue b/src/pages/ConfigurationPage.vue index 23f93a5..8c64ef1 100644 --- a/src/pages/ConfigurationPage.vue +++ b/src/pages/ConfigurationPage.vue @@ -181,6 +181,7 @@ > @@ -303,7 +304,6 @@ export default { methods: { // 初始化 initPage() { - window.configuration = this; // 已启用的 features let activatedFeatures = this.getActivatedFeatures(); // 已启用的命令的 featureCode diff --git a/src/pages/RunCodePage.vue b/src/pages/RunCodePage.vue index d044620..af676e2 100644 --- a/src/pages/RunCodePage.vue +++ b/src/pages/RunCodePage.vue @@ -1,6 +1,6 @@