mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-29 20:32:44 +08:00
优化CodeEditor语言高亮处理:抽取语言映射逻辑到独立方法
This commit is contained in:
parent
2dce359244
commit
932b828de0
@ -15,11 +15,6 @@ import { toRaw } from "vue";
|
|||||||
import importAll from "js/common/importAll.js";
|
import importAll from "js/common/importAll.js";
|
||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
|
|
||||||
// 批量导入声明文件
|
|
||||||
let apis = importAll(
|
|
||||||
require.context("!raw-loader!plugins/monaco/types/", false, /\.ts$/)
|
|
||||||
);
|
|
||||||
|
|
||||||
// 批量导入关键字补全
|
// 批量导入关键字补全
|
||||||
let languageCompletions = importAll(
|
let languageCompletions = importAll(
|
||||||
require.context("plugins/monaco/completions/", false, /\.js$/)
|
require.context("plugins/monaco/completions/", false, /\.js$/)
|
||||||
@ -161,9 +156,7 @@ export default defineComponent({
|
|||||||
immediate: true,
|
immediate: true,
|
||||||
handler(newValue) {
|
handler(newValue) {
|
||||||
if (this.editor) {
|
if (this.editor) {
|
||||||
const language = ["webjavascript", "quickcommand"].includes(newValue)
|
const language = this.getHighlighter(newValue);
|
||||||
? "javascript"
|
|
||||||
: newValue;
|
|
||||||
monaco.editor.setModelLanguage(this.rawEditor().getModel(), language);
|
monaco.editor.setModelLanguage(this.rawEditor().getModel(), language);
|
||||||
this.loadTypes();
|
this.loadTypes();
|
||||||
}
|
}
|
||||||
@ -182,9 +175,7 @@ export default defineComponent({
|
|||||||
methods: {
|
methods: {
|
||||||
// 初始化编辑器
|
// 初始化编辑器
|
||||||
initEditor() {
|
initEditor() {
|
||||||
const language = ["webjavascript", "quickcommand"].includes(this.language)
|
const language = this.getHighlighter(this.language);
|
||||||
? "javascript"
|
|
||||||
: this.language;
|
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
...this.defaultOptions,
|
...this.defaultOptions,
|
||||||
@ -374,6 +365,19 @@ export default defineComponent({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getHighlighter(language) {
|
||||||
|
if (
|
||||||
|
["quickcommand", "javascript", "webjavascript"].includes(
|
||||||
|
language
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return "javascript";
|
||||||
|
}
|
||||||
|
if (language === "cmd") {
|
||||||
|
return "bat";
|
||||||
|
}
|
||||||
|
return language;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
showPlaceholder() {
|
showPlaceholder() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user