mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-07 21:46:12 +08:00
MonocaEditor采用异步加载,优化整体加载速度
This commit is contained in:
parent
325c6c746a
commit
632adf11e1
@ -211,7 +211,8 @@
|
|||||||
class="absolute-bottom"
|
class="absolute-bottom"
|
||||||
:placeholder="true"
|
:placeholder="true"
|
||||||
ref="editor"
|
ref="editor"
|
||||||
@typing="(val) => (quickcommandInfo.cmd = val)"
|
@loaded="monacoInit"
|
||||||
|
@typing="(val) => monacoTyping(val)"
|
||||||
@keyStroke="monacoKeyStroke"
|
@keyStroke="monacoKeyStroke"
|
||||||
:style="{
|
:style="{
|
||||||
top: languageBarHeight + 'px',
|
top: languageBarHeight + 'px',
|
||||||
@ -225,11 +226,15 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import MonacoEditor from "components/MonacoEditor";
|
import { defineAsyncComponent } from "vue";
|
||||||
import CommandSideBar from "components/CommandSideBar";
|
import CommandSideBar from "components/CommandSideBar";
|
||||||
import CommandRunResult from "components/CommandRunResult";
|
import CommandRunResult from "components/CommandRunResult";
|
||||||
import QuickAction from "components/popup/QuickAction";
|
import QuickAction from "components/popup/QuickAction";
|
||||||
import KeyRecorder from "components/popup/KeyRecorder";
|
import KeyRecorder from "components/popup/KeyRecorder";
|
||||||
|
// Monaco改用异步加载
|
||||||
|
const MonacoEditor = defineAsyncComponent(() =>
|
||||||
|
import("components/MonacoEditor")
|
||||||
|
);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@ -270,8 +275,11 @@ export default {
|
|||||||
props: {
|
props: {
|
||||||
action: Object,
|
action: Object,
|
||||||
},
|
},
|
||||||
|
created() {
|
||||||
|
this.commandInit();
|
||||||
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.init();
|
this.sidebarInit();
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
configurationPage() {
|
configurationPage() {
|
||||||
@ -288,23 +296,29 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
init() {
|
// 命令初始化
|
||||||
|
commandInit() {
|
||||||
let quickCommandInfo =
|
let quickCommandInfo =
|
||||||
this.action.type === "run"
|
this.action.type === "run"
|
||||||
? this.$root.utools.getDB("cfg_codeHistory")
|
? this.$root.utools.getDB("cfg_codeHistory")
|
||||||
: this.action.data;
|
: this.action.data;
|
||||||
quickCommandInfo?.program &&
|
quickCommandInfo?.program &&
|
||||||
Object.assign(this.quickcommandInfo, _.cloneDeep(quickCommandInfo));
|
Object.assign(this.quickcommandInfo, _.cloneDeep(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()) {
|
if (this.quickcommandInfo.tags?.includes("默认") && !utools.isDev()) {
|
||||||
this.canCommandSave = false;
|
this.canCommandSave = false;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
// 侧边栏初始化
|
||||||
|
sidebarInit() {
|
||||||
this.$refs.sidebar?.init();
|
this.$refs.sidebar?.init();
|
||||||
},
|
},
|
||||||
|
// Monaco编辑器初始化,Monaco异步加载完执行
|
||||||
|
monacoInit() {
|
||||||
|
this.$refs.editor.setEditorValue(this.quickcommandInfo.cmd);
|
||||||
|
this.setLanguage(this.quickcommandInfo.program);
|
||||||
|
this.$refs.editor.setCursorPosition(this.quickcommandInfo.cursorPosition);
|
||||||
|
},
|
||||||
programChanged(value) {
|
programChanged(value) {
|
||||||
this.setLanguage(value);
|
this.setLanguage(value);
|
||||||
if (value === "custom") this.$refs.settings.show();
|
if (value === "custom") this.$refs.settings.show();
|
||||||
@ -373,6 +387,9 @@ export default {
|
|||||||
command.cursorPosition = this.$refs.editor.getCursorPosition();
|
command.cursorPosition = this.$refs.editor.getCursorPosition();
|
||||||
this.$root.utools.putDB(command, "cfg_codeHistory");
|
this.$root.utools.putDB(command, "cfg_codeHistory");
|
||||||
},
|
},
|
||||||
|
monacoTyping(val) {
|
||||||
|
this.quickcommandInfo.cmd = val;
|
||||||
|
},
|
||||||
monacoKeyStroke(event, data) {
|
monacoKeyStroke(event, data) {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case "run":
|
case "run":
|
||||||
|
@ -46,6 +46,7 @@ export default {
|
|||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.initEditor();
|
this.initEditor();
|
||||||
|
this.$emit("loaded");
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
placeholder: Boolean,
|
placeholder: Boolean,
|
||||||
@ -213,10 +214,13 @@ export default {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
// alt + z 换行
|
// alt + z 换行
|
||||||
this.rawEditor().addCommand(monaco.KeyMod.Alt | monaco.KeyCode.KeyZ, () => {
|
this.rawEditor().addCommand(
|
||||||
that.wordWrap = that.wordWrap === "off" ? "on" : "off";
|
monaco.KeyMod.Alt | monaco.KeyCode.KeyZ,
|
||||||
that.rawEditor.updateOptions({ wordWrap: that.wordWrap });
|
() => {
|
||||||
});
|
that.wordWrap = that.wordWrap === "off" ? "on" : "off";
|
||||||
|
that.rawEditor.updateOptions({ wordWrap: that.wordWrap });
|
||||||
|
}
|
||||||
|
);
|
||||||
// ctrl + s 保存
|
// ctrl + s 保存
|
||||||
this.rawEditor().addCommand(
|
this.rawEditor().addCommand(
|
||||||
monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS,
|
monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user