187187 <span
188188 v-else
189189 style =" display : inline-flex ; align-items : center "
190- @click =" getContent(data.path, data.extension )"
190+ @click =" getContent(data.path)"
191191 >
192192 <template v-if =" isCreate == ' file' && data .id == ' new-file' " >
193193 <div class =" flex justify-between items-center gap-0.5 pr-2" >
@@ -405,6 +405,7 @@ import { MsgError, MsgSuccess, MsgWarning } from '@/utils/message';
405405import { loadMonacoLanguageSupport , setupMonacoEnvironment } from ' @/utils/monaco' ;
406406import { computed , nextTick , onBeforeUnmount , onMounted , reactive , ref } from ' vue' ;
407407import { Languages } from ' @/global/mimetype' ;
408+ import { resolveEditorLanguage } from ' @/utils/file' ;
408409
409410import type { TabPaneName } from ' element-plus' ;
410411import { ElMessageBox , ElTreeV2 } from ' element-plus' ;
@@ -636,20 +637,20 @@ const removeTab = (targetPath: TabPaneName) => {
636637 updateTabs ();
637638 if (fileTabs .value .length > 0 ) {
638639 saveContent ();
639- getContent (selectTab .value , ' ' );
640+ getContent (selectTab .value );
640641 }
641642 })
642643 .catch (() => {
643644 updateTabs ();
644645 isEdit .value = false ;
645646 if (fileTabs .value .length > 0 ) {
646- getContent (selectTab .value , ' ' );
647+ getContent (selectTab .value );
647648 }
648649 });
649650 } else {
650651 updateTabs ();
651652 if (fileTabs .value .length > 0 ) {
652- getContent (selectTab .value , ' ' );
653+ getContent (selectTab .value );
653654 }
654655 }
655656};
@@ -678,7 +679,7 @@ const removeAllTab = (targetPath: string, type: 'left' | 'right' | 'all') => {
678679 selectTab .value = ' ' ;
679680 disposeEditor ();
680681 } else if (newTabs .length > 0 ) {
681- getContent (activeName , ' ' );
682+ getContent (activeName );
682683 }
683684 };
684685
@@ -719,7 +720,7 @@ const removeOtherTab = (targetPath: string) => {
719720 fileTabs .value = [targetTab ];
720721 selectTab .value = targetTab .path ;
721722 saveTabsToStorage ();
722- getContent (targetTab .path , ' ' );
723+ getContent (targetTab .path );
723724 };
724725
725726 const onConfirm = () => {
@@ -749,7 +750,7 @@ const removeOtherTab = (targetPath: string) => {
749750
750751const changeTab = (targetPath : TabPaneName ) => {
751752 selectTab .value = targetPath .toString ();
752- getContent (targetPath .toString (), ' ' );
753+ getContent (targetPath .toString ());
753754};
754755
755756const eols = computed (() => [
@@ -1040,6 +1041,7 @@ const acceptParams = async (props: EditProps) => {
10401041 directoryPath .value = getDirectoryPath (props .path );
10411042 fileExtension .value = props .extension ;
10421043 fileName .value = props .name ;
1044+ config .language = resolveEditorLanguage (props .path , props .extension , props .name );
10431045
10441046 let savedTabs = loadTabsFromStorage ();
10451047 const withoutCurrent = savedTabs .filter ((tab ) => tab .path !== props .path );
@@ -1059,7 +1061,9 @@ const acceptParams = async (props: EditProps) => {
10591061 fileTabs .value = merged .slice (- maxTabs );
10601062 selectTab .value = props .path ;
10611063
1062- config .language = props .language ;
1064+ if (props .language ) {
1065+ config .language = props .language ;
1066+ }
10631067 config .eol = monaco .editor .EndOfLineSequence .LF ;
10641068 config .theme = localStorage .getItem (codeThemeKey ) || ' vs-dark' ;
10651069 config .wordWrap = (localStorage .getItem (warpKey ) as WordWrapOptions ) || ' on' ;
@@ -1140,7 +1144,7 @@ const getRefresh = (path: string) => {
11401144 }
11411145};
11421146
1143- const getContent = (path : string , extension : string , forceReload = false ) => {
1147+ const getContent = (path : string , forceReload = false ) => {
11441148 if (! forceReload && (form .value .path === path || isCreate .value == ' file' )) {
11451149 return ;
11461150 }
@@ -1152,31 +1156,15 @@ const getContent = (path: string, extension: string, forceReload = false) => {
11521156 codeReq .path = path ;
11531157 codeReq .expand = true ;
11541158
1155- if (extension !== ' ' ) {
1156- Languages .forEach ((language ) => {
1157- const ext = extension .substring (1 );
1158- if (language .value .indexOf (ext ) > - 1 ) {
1159- config .language = language .label ;
1160- }
1161- });
1162- }
1163-
11641159 getFileContent (codeReq )
11651160 .then ((res ) => {
11661161 form .value .content = res .data .content ;
11671162 oldFileContent .value = res .data .content ;
11681163 form .value .path = res .data .path ;
11691164 fileExtension .value = res .data .extension ;
11701165 fileName .value = res .data .name ;
1166+ config .language = resolveEditorLanguage (res .data .path , res .data .extension , res .data .name );
11711167 initEditor ();
1172- if (extension == ' ' ) {
1173- Languages .forEach ((language ) => {
1174- const ext = fileExtension .value .substring (1 );
1175- if (language .value .indexOf (ext ) > - 1 ) {
1176- config .language = language .label ;
1177- }
1178- });
1179- }
11801168 const exists = fileTabs .value .some ((tab ) => tab .path === path );
11811169 if (exists ) {
11821170 const tab = fileTabs .value .find ((t ) => t .path === path );
@@ -1215,7 +1203,7 @@ const getContent = (path: string, extension: string, forceReload = false) => {
12151203
12161204const handleHistoryRestored = (path : string ) => {
12171205 if (path === form .value .path ) {
1218- getContent (path , ' ' , true );
1206+ getContent (path , true );
12191207 loadHistoryVersionCount (path );
12201208 }
12211209};
0 commit comments