@@ -13,7 +13,7 @@ import { IPath } from 'vs/platform/windows/common/windows';
1313import { Event as CommonEvent , Emitter } from 'vs/base/common/event' ;
1414import { isWindows , isMacintosh } from 'vs/base/common/platform' ;
1515import { IWorkspaceIdentifier , IWorkspacesMainService , ISingleFolderWorkspaceIdentifier , isSingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces' ;
16- import { IHistoryMainService , IRecentlyOpened , isRecentWorkspace , isRecentFolder , IRecent , isRecentFile } from 'vs/platform/history/common/history' ;
16+ import { IHistoryMainService , IRecentlyOpened , isRecentWorkspace , isRecentFolder , IRecent , isRecentFile , IRecentFolder , IRecentWorkspace , IRecentFile } from 'vs/platform/history/common/history' ;
1717import { RunOnceScheduler } from 'vs/base/common/async' ;
1818import { isEqual as areResourcesEqual , dirname , originalFSPath } from 'vs/base/common/resources' ;
1919import { URI } from 'vs/base/common/uri' ;
@@ -51,15 +51,15 @@ export class HistoryMainService implements IHistoryMainService {
5151
5252 for ( let curr of newlyAdded ) {
5353 if ( isRecentWorkspace ( curr ) ) {
54- if ( ! this . workspacesMainService . isUntitledWorkspace ( curr . workspace ) && indexOfWorkspace ( mru . workspaces , curr . workspace ) >= 0 ) {
54+ if ( ! this . workspacesMainService . isUntitledWorkspace ( curr . workspace ) && indexOfWorkspace ( mru . workspaces , curr . workspace ) === - 1 ) {
5555 mru . workspaces . unshift ( curr ) ;
5656 }
5757 } else if ( isRecentFolder ( curr ) ) {
58- if ( indexOfFolder ( mru . workspaces , curr . folderUri ) >= 0 ) {
58+ if ( indexOfFolder ( mru . workspaces , curr . folderUri ) === - 1 ) {
5959 mru . workspaces . unshift ( curr ) ;
6060 }
6161 } else {
62- if ( indexOfFile ( mru . files , curr . fileUri ) >= 0 ) {
62+ if ( indexOfFile ( mru . files , curr . fileUri ) === - 1 ) {
6363 mru . files . unshift ( curr ) ;
6464 // Add to recent documents (Windows only, macOS later)
6565 if ( isWindows && curr . fileUri . scheme === Schemas . file ) {
@@ -150,28 +150,45 @@ export class HistoryMainService implements IHistoryMainService {
150150
151151 getRecentlyOpened ( currentWorkspace ?: IWorkspaceIdentifier , currentFolder ?: ISingleFolderWorkspaceIdentifier , currentFiles ?: IPath [ ] ) : IRecentlyOpened {
152152
153- // Get from storage
154- let { workspaces , files } = this . getRecentlyOpenedFromStorage ( ) ;
153+ const workspaces : Array < IRecentFolder | IRecentWorkspace > = [ ] ;
154+ const files : IRecentFile [ ] = [ ] ;
155155
156156 // Add current workspace to beginning if set
157- if ( currentWorkspace && ! this . workspacesMainService . isUntitledWorkspace ( currentWorkspace ) && ! workspaces . some ( w => isRecentWorkspace ( w ) && w . workspace . id === currentWorkspace . id ) ) {
158- workspaces . unshift ( { workspace : currentWorkspace } ) ;
157+ if ( currentWorkspace && ! this . workspacesMainService . isUntitledWorkspace ( currentWorkspace ) ) {
158+ workspaces . push ( { workspace : currentWorkspace } ) ;
159159 }
160-
161- if ( currentFolder && ! workspaces . some ( w => isRecentFolder ( w ) && areResourcesEqual ( w . folderUri , currentFolder ) ) ) {
162- workspaces . unshift ( { folderUri : currentFolder } ) ;
160+ if ( currentFolder ) {
161+ workspaces . push ( { folderUri : currentFolder } ) ;
163162 }
164163
165164 // Add currently files to open to the beginning if any
166165 if ( currentFiles ) {
167166 for ( let currentFile of currentFiles ) {
168167 const fileUri = currentFile . fileUri ;
169- if ( fileUri && ! files . some ( f => areResourcesEqual ( f . fileUri , fileUri ) ) ) {
170- files . unshift ( { fileUri } ) ;
168+ if ( fileUri && indexOfFile ( files , fileUri ) === - 1 ) {
169+ files . push ( { fileUri } ) ;
171170 }
172171 }
173172 }
174173
174+ // Get from storage
175+ let recents = this . getRecentlyOpenedFromStorage ( ) ;
176+ for ( let recent of recents . workspaces ) {
177+ let index = isRecentFolder ( recent ) ? indexOfFolder ( workspaces , recent . folderUri ) : indexOfWorkspace ( workspaces , recent . workspace ) ;
178+ if ( index >= 0 ) {
179+ workspaces [ index ] . label = workspaces [ index ] . label || recent . label ;
180+ } else {
181+ workspaces . push ( recent ) ;
182+ }
183+ }
184+ for ( let recent of recents . files ) {
185+ let index = indexOfFile ( files , recent . fileUri ) ;
186+ if ( index >= 0 ) {
187+ files [ index ] . label = files [ index ] . label || recent . label ;
188+ } else {
189+ files . push ( recent ) ;
190+ }
191+ }
175192 return { workspaces, files } ;
176193 }
177194
@@ -280,14 +297,14 @@ function location(recent: IRecent): URI {
280297 return recent . workspace . configPath ;
281298}
282299
283- function indexOfWorkspace ( arr : Array < IRecent > , workspace : IWorkspaceIdentifier ) : number {
300+ function indexOfWorkspace ( arr : IRecent [ ] , workspace : IWorkspaceIdentifier ) : number {
284301 return arrays . firstIndex ( arr , w => isRecentWorkspace ( w ) && w . workspace . id === workspace . id ) ;
285302}
286303
287- function indexOfFolder ( arr : Array < IRecent > , folderURI : ISingleFolderWorkspaceIdentifier ) : number {
304+ function indexOfFolder ( arr : IRecent [ ] , folderURI : ISingleFolderWorkspaceIdentifier ) : number {
288305 return arrays . firstIndex ( arr , f => isRecentFolder ( f ) && areResourcesEqual ( f . folderUri , folderURI ) ) ;
289306}
290307
291- function indexOfFile ( arr : Array < IRecent > , fileURI : URI ) : number {
292- return arrays . firstIndex ( arr , f => isRecentFile ( f ) && areResourcesEqual ( f . fileUri , fileURI ) ) ;
308+ function indexOfFile ( arr : IRecentFile [ ] , fileURI : URI ) : number {
309+ return arrays . firstIndex ( arr , f => areResourcesEqual ( f . fileUri , fileURI ) ) ;
293310}
0 commit comments