修复 editor 判断语言

This commit is contained in:
whyour
2023-08-05 13:18:28 +08:00
parent b1a242c8ee
commit a2e33d1ed4
6 changed files with 35 additions and 44 deletions
+3 -16
View File
@@ -8,22 +8,9 @@ import Editor from '@monaco-editor/react';
import SaveModal from './saveModal';
import SettingModal from './setting';
import { useTheme } from '@/utils/hooks';
import { logEnded } from '@/utils';
import { getEditorMode, logEnded } from '@/utils';
const { Option } = Select;
const LangMap: any = {
'.py': 'python',
'.js': 'javascript',
'.mjs': 'typescript',
'.sh': 'shell',
'.ts': 'typescript',
};
const prefixMap: any = {
python: '.py',
javascript: '.js',
shell: '.sh',
typescript: '.ts',
};
const EditModal = ({
treeData,
@@ -66,7 +53,7 @@ const EditModal = ({
return;
}
const newMode = LangMap[value.slice(-3)] || '';
const newMode = getEditorMode(value);
setCNode(node);
setLanguage(newMode);
getDetail(node);
@@ -146,7 +133,7 @@ const EditModal = ({
setCNode(currentNode);
setValue(content as string);
setSelectedKey(currentNode.key);
const newMode = LangMap[currentNode.title.slice(-3)] || '';
const newMode = getEditorMode(currentNode.title);
setLanguage(newMode);
}
}, [content, currentNode]);