diff --git a/src/vs/base/common/comparers.ts b/src/vs/base/common/comparers.ts index 70b404ca558f0a650c058474afe4e55e10b7dfbb..c2448ce4dd1e2d49fee9db8908e01977733bd95d 100644 --- a/src/vs/base/common/comparers.ts +++ b/src/vs/base/common/comparers.ts @@ -15,7 +15,7 @@ export function setFileNameComparer(collator: Intl.Collator): void { intlFileNameCollatorIsNumeric = collator.resolvedOptions().numeric; } -export function compareFileNames(one: string, other: string): number { +export function compareFileNames(one: string, other: string, caseSensitive = false): number { if (intlFileNameCollator) { const a = one || ''; const b = other || ''; @@ -30,14 +30,19 @@ export function compareFileNames(one: string, other: string): number { return result; } - return noIntlCompareFileNames(one, other); + return noIntlCompareFileNames(one, other, caseSensitive); } const FileNameMatch = /^(.*?)(\.([^.]*))?$/; -export function noIntlCompareFileNames(one: string, other: string): number { - const [oneName, oneExtension] = extractNameAndExtension(one, true); - const [otherName, otherExtension] = extractNameAndExtension(other, true); +export function noIntlCompareFileNames(one: string, other: string, caseSensitive = false): number { + if (!caseSensitive) { + one = one && one.toLowerCase(); + other = other && other.toLowerCase(); + } + + const [oneName, oneExtension] = extractNameAndExtension(one); + const [otherName, otherExtension] = extractNameAndExtension(other); if (oneName !== otherName) { return oneName < otherName ? -1 : 1; @@ -79,8 +84,8 @@ export function compareFileExtensions(one: string, other: string): number { } function noIntlCompareFileExtensions(one: string, other: string): number { - const [oneName, oneExtension] = extractNameAndExtension(one, true); - const [otherName, otherExtension] = extractNameAndExtension(other, true); + const [oneName, oneExtension] = extractNameAndExtension(one && one.toLowerCase()); + const [otherName, otherExtension] = extractNameAndExtension(other && other.toLowerCase()); if (oneExtension !== otherExtension) { return oneExtension < otherExtension ? -1 : 1; @@ -93,32 +98,49 @@ function noIntlCompareFileExtensions(one: string, other: string): number { return oneName < otherName ? -1 : 1; } -function extractNameAndExtension(str?: string, lowercase?: boolean): [string, string] { - const match = str ? FileNameMatch.exec(lowercase ? str.toLowerCase() : str) : [] as RegExpExecArray; +function extractNameAndExtension(str?: string): [string, string] { + const match = str ? FileNameMatch.exec(str) : [] as RegExpExecArray; return [(match && match[1]) || '', (match && match[3]) || '']; } -export function comparePaths(one: string, other: string): number { +function comparePathComponents(one: string, other: string, caseSensitive = false): number { + if (!caseSensitive) { + one = one && one.toLowerCase(); + other = other && other.toLowerCase(); + } + + if (one === other) { + return 0; + } + + return one < other ? -1 : 1; +} + +export function comparePaths(one: string, other: string, caseSensitive = false): number { const oneParts = one.split(paths.nativeSep); const otherParts = other.split(paths.nativeSep); const lastOne = oneParts.length - 1; const lastOther = otherParts.length - 1; - let endOne: boolean, endOther: boolean, onePart: string, otherPart: string; + let endOne: boolean, endOther: boolean; for (let i = 0; ; i++) { endOne = lastOne === i; endOther = lastOther === i; if (endOne && endOther) { - return compareFileNames(oneParts[i], otherParts[i]); + return compareFileNames(oneParts[i], otherParts[i], caseSensitive); } else if (endOne) { return -1; } else if (endOther) { return 1; - } else if ((onePart = oneParts[i].toLowerCase()) !== (otherPart = otherParts[i].toLowerCase())) { - return onePart < otherPart ? -1 : 1; + } + + const result = comparePathComponents(oneParts[i], otherParts[i], caseSensitive); + + if (result !== 0) { + return result; } } } diff --git a/src/vs/workbench/api/node/extHostSCM.ts b/src/vs/workbench/api/node/extHostSCM.ts index bcd3a92b97cba8860b67b8914a72ea254bcaa292..f2c06ca627060942d262c76e51ecaad8060a2ecb 100644 --- a/src/vs/workbench/api/node/extHostSCM.ts +++ b/src/vs/workbench/api/node/extHostSCM.ts @@ -93,7 +93,7 @@ function compareResourceStatesDecorations(a: vscode.SourceControlResourceDecorat } function compareResourceStates(a: vscode.SourceControlResourceState, b: vscode.SourceControlResourceState): number { - let result = comparePaths(a.resourceUri.fsPath, b.resourceUri.fsPath); + let result = comparePaths(a.resourceUri.fsPath, b.resourceUri.fsPath, true); if (result !== 0) { return result; @@ -234,6 +234,8 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG const snapshot = [...this._resourceStates].sort(compareResourceStates); const diffs = sortedDiff(this._resourceSnapshot, snapshot, compareResourceStates); + console.log(diffs); + const splices = diffs.map>(diff => { const toInsert = diff.toInsert.map(r => { const handle = this._resourceHandlePool++;