优化CodeEditor语言高亮处理:抽取语言映射逻辑到独立方法

This commit is contained in:
fofolee 2025-01-25 17:36:11 +08:00
parent 2dce359244
commit 932b828de0

View File

@ -15,11 +15,6 @@ import { toRaw } from "vue";
import importAll from "js/common/importAll.js";
import { defineComponent } from "vue";
//
let apis = importAll(
require.context("!raw-loader!plugins/monaco/types/", false, /\.ts$/)
);
//
let languageCompletions = importAll(
require.context("plugins/monaco/completions/", false, /\.js$/)
@ -161,9 +156,7 @@ export default defineComponent({
immediate: true,
handler(newValue) {
if (this.editor) {
const language = ["webjavascript", "quickcommand"].includes(newValue)
? "javascript"
: newValue;
const language = this.getHighlighter(newValue);
monaco.editor.setModelLanguage(this.rawEditor().getModel(), language);
this.loadTypes();
}
@ -182,9 +175,7 @@ export default defineComponent({
methods: {
//
initEditor() {
const language = ["webjavascript", "quickcommand"].includes(this.language)
? "javascript"
: this.language;
const language = this.getHighlighter(this.language);
const options = {
...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: {
showPlaceholder() {