From fd281a7eb66db0d254293cc7fc419c5d7a77f071 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 21 Jul 2017 10:52:56 +0200 Subject: [PATCH] fix casing in recently opened --- .../history/electron-main/historyMainService.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/vs/platform/history/electron-main/historyMainService.ts b/src/vs/platform/history/electron-main/historyMainService.ts index 8f7c8e6b466..ff277d03e5f 100644 --- a/src/vs/platform/history/electron-main/historyMainService.ts +++ b/src/vs/platform/history/electron-main/historyMainService.ts @@ -19,6 +19,7 @@ import { isWindows, isMacintosh, isLinux } from 'vs/base/common/platform'; import { IWorkspaceIdentifier, IWorkspacesMainService, getWorkspaceLabel, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, IWorkspaceSavedEvent } from "vs/platform/workspaces/common/workspaces"; import { IHistoryMainService, IRecentlyOpened } from "vs/platform/history/common/history"; import { IEnvironmentService } from "vs/platform/environment/common/environment"; +import { isEqual } from "vs/base/common/paths"; export interface ILegacyRecentlyOpened extends IRecentlyOpened { folders: string[]; // TODO@Ben migration @@ -77,7 +78,7 @@ export class HistoryMainService implements IHistoryMainService { // Files files.forEach((path) => { mru.files.unshift(path); - mru.files = arrays.distinct(mru.files, f => isLinux ? f : f.toLowerCase()); + mru.files = arrays.distinct(mru.files, file => this.distinctFn(file)); // Add to recent documents (Windows/macOS only) if (isMacintosh || isWindows) { @@ -101,14 +102,14 @@ export class HistoryMainService implements IHistoryMainService { pathsToRemove.forEach((pathToRemove => { // Remove workspace - let index = arrays.firstIndex(mru.workspaces, workspace => isSingleFolderWorkspaceIdentifier(workspace) ? workspace === pathToRemove : workspace.configPath === pathToRemove); + let index = arrays.firstIndex(mru.workspaces, workspace => isEqual(isSingleFolderWorkspaceIdentifier(workspace) ? workspace : workspace.configPath, pathToRemove, !isLinux /* ignorecase */)); if (index >= 0) { mru.workspaces.splice(index, 1); update = true; } // Remove file - index = mru.files.indexOf(pathToRemove); + index = arrays.firstIndex(mru.files, file => isEqual(file, pathToRemove, !isLinux /* ignorecase */)); if (index >= 0) { mru.files.splice(index, 1); update = true; @@ -155,7 +156,7 @@ export class HistoryMainService implements IHistoryMainService { // Clear those dupes workspaces = arrays.distinct(workspaces, workspace => this.distinctFn(workspace)); - files = arrays.distinct(files); + files = arrays.distinct(files, file => this.distinctFn(file)); // Hide untitled workspaces workspaces = workspaces.filter(workspace => isSingleFolderWorkspaceIdentifier(workspace) || !this.workspacesService.isUntitledWorkspace(workspace)); @@ -163,12 +164,12 @@ export class HistoryMainService implements IHistoryMainService { return { workspaces, files }; } - private distinctFn(workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier): string { - if (isSingleFolderWorkspaceIdentifier(workspace)) { - return isLinux ? workspace : workspace.toLowerCase(); + private distinctFn(workspaceOrFile: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | string): string { + if (isSingleFolderWorkspaceIdentifier(workspaceOrFile) || typeof workspaceOrFile === 'string') { + return isLinux ? workspaceOrFile : workspaceOrFile.toLowerCase(); } - return workspace.id + (isLinux ? workspace.configPath : workspace.configPath.toLowerCase()); // ID and configPath form a unique workspace + return workspaceOrFile.id + (isLinux ? workspaceOrFile.configPath : workspaceOrFile.configPath.toLowerCase()); // ID and configPath form a unique workspace } private saveRecentlyOpened(recent: IRecentlyOpened): void { -- GitLab