提交 7faf2a05 编写于 作者: J Joao Moreno

🐛 add sorting to scm viewlet

fixes #22681
上级 4b77b71b
......@@ -6,6 +6,7 @@
import scorer = require('vs/base/common/scorer');
import strings = require('vs/base/common/strings');
import * as paths from 'vs/base/common/paths';
let intlFileNameCollator: Intl.Collator;
let intlFileNameCollatorIsNumeric: boolean;
......@@ -56,6 +57,30 @@ export function noIntlCompareFileNames(one: string, other: string): number {
return oneExtension < otherExtension ? -1 : 1;
}
export function comparePaths(one: string, other: string): 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;
for (let i = 0; ; i++) {
endOne = lastOne === i;
endOther = lastOther === i;
if (endOne && endOther) {
return compareFileNames(oneParts[i], otherParts[i]);
} 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;
}
}
}
export function compareAnything(one: string, other: string, lookFor: string): number {
let elementAName = one.toLowerCase();
let elementBName = other.toLowerCase();
......
......@@ -36,6 +36,7 @@ import { ActionBar, IActionItemProvider } from 'vs/base/browser/ui/actionbar/act
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/themeService';
import { InputBox } from 'vs/base/browser/ui/inputbox/inputBox';
import { IModelService } from 'vs/editor/common/services/modelService';
import { comparePaths } from 'vs/base/common/comparers';
function isSCMResource(element: ISCMResourceGroup | ISCMResource): element is ISCMResource {
return !!(element as ISCMResource).uri;
......@@ -153,6 +154,10 @@ class Delegate implements IDelegate<ISCMResourceGroup | ISCMResource> {
}
}
function resourceSorter(a: ISCMResource, b: ISCMResource): number {
return comparePaths(a.uri.fsPath, b.uri.fsPath);
}
export class SCMViewlet extends Viewlet {
private cachedDimension: Dimension;
......@@ -258,7 +263,7 @@ export class SCMViewlet extends Viewlet {
}
const elements = provider.resources
.reduce<(ISCMResourceGroup | ISCMResource)[]>((r, g) => [...r, g, ...g.resources], []);
.reduce<(ISCMResourceGroup | ISCMResource)[]>((r, g) => [...r, g, ...g.resources.sort(resourceSorter)], []);
this.list.splice(0, this.list.length, elements);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册