@@ -522,6 +522,26 @@ monaco.editor.defineTheme('vs', {
522522
523523const selectTab = ref ();
524524const fileTabs = ref ([]);
525+ const maxTabs = 10 ;
526+ const codeTabsStorageKey = ' code-editor-tabs' ;
527+
528+ const saveTabsToStorage = () => {
529+ const simpleTabs = fileTabs .value .map ((tab : any ) => ({
530+ path: tab .path ,
531+ name: tab .name ,
532+ }));
533+ localStorage .setItem (codeTabsStorageKey , JSON .stringify (simpleTabs .slice (0 , maxTabs )));
534+ };
535+
536+ const loadTabsFromStorage = (): { path: string ; name: string }[] => {
537+ const raw = localStorage .getItem (codeTabsStorageKey );
538+ if (! raw ) return [];
539+ const parsed = JSON .parse (raw );
540+ if (Array .isArray (parsed )) {
541+ return parsed .filter ((item ) => item && item .path && item .name );
542+ }
543+ return [];
544+ };
525545const removeTab = (targetPath : TabPaneName ) => {
526546 const tabs = fileTabs .value ;
527547 let activeName = selectTab .value ;
@@ -890,19 +910,19 @@ const acceptParams = (props: EditProps) => {
890910 directoryPath .value = getDirectoryPath (props .path );
891911 fileExtension .value = props .extension ;
892912 fileName .value = props .name ;
893- fileTabs .value = [];
894- selectTab .value = ' ' ;
895- fileTabs .value .push ({
896- name: fileName .value ,
897- path: props .path ,
898- });
913+ const savedTabs = loadTabsFromStorage ();
914+ const withoutCurrent = savedTabs .filter ((tab ) => tab .path !== props .path );
915+ const merged = [... withoutCurrent , { path: props .path , name: props .name }];
916+ fileTabs .value = merged .slice (- maxTabs );
899917 selectTab .value = props .path ;
918+
900919 config .language = props .language ;
901920 config .eol = monaco .editor .EndOfLineSequence .LF ;
902921 config .theme = localStorage .getItem (codeThemeKey ) || ' vs-dark' ;
903922 config .wordWrap = (localStorage .getItem (warpKey ) as WordWrapOptions ) || ' on' ;
904923 config .minimap = localStorage .getItem (minimapKey ) !== null ? localStorage .getItem (minimapKey ) === ' true' : true ;
905924 open .value = true ;
925+ saveTabsToStorage ();
906926};
907927
908928const getIconName = (extension : string ) => getIcon (extension );
@@ -969,6 +989,10 @@ const getContent = (path: string, extension: string) => {
969989 if (form .value .path === path || isCreate .value == ' file' ) {
970990 return ;
971991 }
992+ const existsInTabs = fileTabs .value .some ((tab ) => tab .path === path );
993+ if (! existsInTabs && fileTabs .value .length >= maxTabs ) {
994+ fileTabs .value .shift ();
995+ }
972996 const fetchFileContent = () => {
973997 codeReq .path = path ;
974998 codeReq .expand = true ;
@@ -999,12 +1023,17 @@ const getContent = (path: string, extension: string) => {
9991023 });
10001024 }
10011025 const exists = fileTabs .value .some ((tab ) => tab .path === path );
1002- if (! exists ) {
1026+ if (exists ) {
1027+ fileTabs .value = fileTabs .value
1028+ .filter ((t ) => t .path !== path )
1029+ .concat ([{ name: res .data .name , path: res .data .path }]);
1030+ } else {
10031031 fileTabs .value .push ({
10041032 name: res .data .name ,
1005- path: path ,
1033+ path: res . data . path ,
10061034 });
10071035 }
1036+ saveTabsToStorage ();
10081037 selectTab .value = res .data .path ;
10091038 })
10101039 .catch (() => {});
0 commit comments