@@ -48,38 +48,44 @@ export class HistoryMainService implements IHistoryMainService {
4848 }
4949
5050 addRecentlyOpened ( newlyAdded : IRecent [ ] ) : void {
51- const mru = this . getRecentlyOpened ( ) ;
51+ const workspaces : Array < IRecentFolder | IRecentWorkspace > = [ ] ;
52+ const files : IRecentFile [ ] = [ ] ;
5253
5354 for ( let curr of newlyAdded ) {
5455 if ( isRecentWorkspace ( curr ) ) {
55- if ( ! this . workspacesMainService . isUntitledWorkspace ( curr . workspace ) && indexOfWorkspace ( mru . workspaces , curr . workspace ) === - 1 ) {
56- mru . workspaces . unshift ( curr ) ;
56+ if ( ! this . workspacesMainService . isUntitledWorkspace ( curr . workspace ) && indexOfWorkspace ( workspaces , curr . workspace ) === - 1 ) {
57+ workspaces . push ( curr ) ;
5758 }
5859 } else if ( isRecentFolder ( curr ) ) {
59- if ( indexOfFolder ( mru . workspaces , curr . folderUri ) === - 1 ) {
60- mru . workspaces . unshift ( curr ) ;
60+ if ( indexOfFolder ( workspaces , curr . folderUri ) === - 1 ) {
61+ workspaces . push ( curr ) ;
6162 }
6263 } else {
63- if ( indexOfFile ( mru . files , curr . fileUri ) === - 1 ) {
64- mru . files . unshift ( curr ) ;
64+ if ( indexOfFile ( files , curr . fileUri ) === - 1 ) {
65+ files . push ( curr ) ;
6566 // Add to recent documents (Windows only, macOS later)
6667 if ( isWindows && curr . fileUri . scheme === Schemas . file ) {
6768 app . addRecentDocument ( curr . fileUri . fsPath ) ;
6869 }
6970 }
7071 }
72+ }
7173
72- // Make sure its bounded
73- mru . workspaces = mru . workspaces . slice ( 0 , HistoryMainService . MAX_TOTAL_RECENT_ENTRIES ) ;
74- mru . files = mru . files . slice ( 0 , HistoryMainService . MAX_TOTAL_RECENT_ENTRIES ) ;
74+ this . addEntriesFromStorage ( workspaces , files ) ;
7575
76- this . saveRecentlyOpened ( mru ) ;
77- this . _onRecentlyOpenedChange . fire ( ) ;
76+ if ( workspaces . length > HistoryMainService . MAX_TOTAL_RECENT_ENTRIES ) {
77+ workspaces . length = HistoryMainService . MAX_TOTAL_RECENT_ENTRIES ;
78+ }
79+ if ( files . length > HistoryMainService . MAX_TOTAL_RECENT_ENTRIES ) {
80+ files . length = HistoryMainService . MAX_TOTAL_RECENT_ENTRIES ;
81+ }
7882
79- // Schedule update to recent documents on macOS dock
80- if ( isMacintosh ) {
81- this . macOSRecentDocumentsUpdater . trigger ( ( ) => this . updateMacOSRecentDocuments ( ) ) ;
82- }
83+ this . saveRecentlyOpened ( { workspaces, files } ) ;
84+ this . _onRecentlyOpenedChange . fire ( ) ;
85+
86+ // Schedule update to recent documents on macOS dock
87+ if ( isMacintosh ) {
88+ this . macOSRecentDocumentsUpdater . trigger ( ( ) => this . updateMacOSRecentDocuments ( ) ) ;
8389 }
8490 }
8591
@@ -177,7 +183,12 @@ export class HistoryMainService implements IHistoryMainService {
177183 }
178184 }
179185 }
186+ this . addEntriesFromStorage ( workspaces , files ) ;
180187
188+ return { workspaces, files } ;
189+ }
190+
191+ private addEntriesFromStorage ( workspaces : Array < IRecentFolder | IRecentWorkspace > , files : IRecentFile [ ] ) {
181192 // Get from storage
182193 let recents = this . getRecentlyOpenedFromStorage ( ) ;
183194 for ( let recent of recents . workspaces ) {
@@ -196,7 +207,6 @@ export class HistoryMainService implements IHistoryMainService {
196207 files . push ( recent ) ;
197208 }
198209 }
199- return { workspaces, files } ;
200210 }
201211
202212 private getRecentlyOpenedFromStorage ( ) : IRecentlyOpened {
0 commit comments