Browse Source

Closes #547 - Adds natural sorting to branches, tags, and files

main
Eric Amodio 6 years ago
parent
commit
84f7ee93c6
11 changed files with 34 additions and 21 deletions
  1. +6
    -2
      src/quickpicks/branchesAndTagsQuickPick.ts
  2. +3
    -1
      src/quickpicks/repoStatusQuickPick.ts
  3. +3
    -4
      src/views/nodes/branchesNode.ts
  4. +3
    -1
      src/views/nodes/commitNode.ts
  5. +1
    -1
      src/views/nodes/folderNode.ts
  6. +5
    -7
      src/views/nodes/remoteNode.ts
  7. +1
    -1
      src/views/nodes/remotesNode.ts
  8. +5
    -1
      src/views/nodes/resultsFilesNode.ts
  9. +1
    -1
      src/views/nodes/stashNode.ts
  10. +5
    -1
      src/views/nodes/statusFilesNode.ts
  11. +1
    -1
      src/views/nodes/tagsNode.ts

+ 6
- 2
src/quickpicks/branchesAndTagsQuickPick.ts View File

@ -265,7 +265,11 @@ export class BranchesAndTagsQuickPick {
const filter = const filter =
filters !== undefined && typeof filters.branches === 'function' ? filters.branches : undefined; filters !== undefined && typeof filters.branches === 'function' ? filters.branches : undefined;
branches.sort((a, b) => (b.remote ? -1 : 1) - (a.remote ? -1 : 1) || a.name.localeCompare(b.name));
branches.sort(
(a, b) =>
(b.remote ? -1 : 1) - (a.remote ? -1 : 1) ||
a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' })
);
for (const b of branches) { for (const b of branches) {
if (filter !== undefined && !filter(b)) continue; if (filter !== undefined && !filter(b)) continue;
@ -276,7 +280,7 @@ export class BranchesAndTagsQuickPick {
if (tags !== undefined) { if (tags !== undefined) {
const filter = filters !== undefined && typeof filters.tags === 'function' ? filters.tags : undefined; const filter = filters !== undefined && typeof filters.tags === 'function' ? filters.tags : undefined;
tags.sort((a, b) => a.name.localeCompare(b.name));
tags.sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }));
for (const t of tags) { for (const t of tags) {
if (filter !== undefined && !filter(t)) continue; if (filter !== undefined && !filter(t)) continue;

+ 3
- 1
src/quickpicks/repoStatusQuickPick.ts View File

@ -224,7 +224,9 @@ export class RepoStatusQuickPick {
((a as OpenStatusFileCommandQuickPickItem).status.staged ? -1 : 1) - ((a as OpenStatusFileCommandQuickPickItem).status.staged ? -1 : 1) -
((b as OpenStatusFileCommandQuickPickItem).status.staged ? -1 : 1) || ((b as OpenStatusFileCommandQuickPickItem).status.staged ? -1 : 1) ||
(a as OpenStatusFileCommandQuickPickItem).status.fileName.localeCompare( (a as OpenStatusFileCommandQuickPickItem).status.fileName.localeCompare(
(b as OpenStatusFileCommandQuickPickItem).status.fileName
(b as OpenStatusFileCommandQuickPickItem).status.fileName,
undefined,
{ numeric: true, sensitivity: 'base' }
) )
); );

+ 3
- 4
src/views/nodes/branchesNode.ts View File

@ -30,13 +30,12 @@ export class BranchesNode extends ViewNode {
const branches = await this.repo.getBranches(); const branches = await this.repo.getBranches();
if (branches === undefined) return []; if (branches === undefined) return [];
branches.sort((a, b) => a.name.localeCompare(b.name));
branches.sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }));
// filter local branches // filter local branches
const branchNodes = [ const branchNodes = [
...Iterables.filterMap(
branches,
b => (b.remote ? undefined : new BranchNode(this.uri, this.view, this, b))
...Iterables.filterMap(branches, b =>
b.remote ? undefined : new BranchNode(this.uri, this.view, this, b)
) )
]; ];
if (this.view.config.branches.layout === ViewBranchesLayout.List) return branchNodes; if (this.view.config.branches.layout === ViewBranchesLayout.List) return branchNodes;

+ 3
- 1
src/views/nodes/commitNode.ts View File

@ -48,7 +48,9 @@ export class CommitNode extends ViewRefNode {
children = (await root.getChildren()) as FileNode[]; children = (await root.getChildren()) as FileNode[];
} }
else { else {
children.sort((a, b) => a.label!.localeCompare(b.label!));
children.sort((a, b) =>
a.label!.localeCompare(b.label!, undefined, { numeric: true, sensitivity: 'base' })
);
} }
return children; return children;
} }

+ 1
- 1
src/views/nodes/folderNode.ts View File

@ -61,7 +61,7 @@ export class FolderNode extends ViewNode {
return ( return (
(a instanceof FolderNode ? -1 : 1) - (b instanceof FolderNode ? -1 : 1) || (a instanceof FolderNode ? -1 : 1) - (b instanceof FolderNode ? -1 : 1) ||
a.priority - b.priority || a.priority - b.priority ||
a.label!.localeCompare(b.label!)
a.label!.localeCompare(b.label!, undefined, { numeric: true, sensitivity: 'base' })
); );
}); });

+ 5
- 7
src/views/nodes/remoteNode.ts View File

@ -29,16 +29,14 @@ export class RemoteNode extends ViewNode {
const branches = await this.repo.getBranches(); const branches = await this.repo.getBranches();
if (branches === undefined) return []; if (branches === undefined) return [];
branches.sort((a, b) => a.name.localeCompare(b.name));
branches.sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }));
// filter remote branches // filter remote branches
const branchNodes = [ const branchNodes = [
...Iterables.filterMap(
branches,
b =>
!b.remote || !b.name.startsWith(this.remote.name)
? undefined
: new BranchNode(this.uri, this.view, this, b)
...Iterables.filterMap(branches, b =>
!b.remote || !b.name.startsWith(this.remote.name)
? undefined
: new BranchNode(this.uri, this.view, this, b)
) )
]; ];
if (this.view.config.branches.layout === ViewBranchesLayout.List) return branchNodes; if (this.view.config.branches.layout === ViewBranchesLayout.List) return branchNodes;

+ 1
- 1
src/views/nodes/remotesNode.ts View File

@ -28,7 +28,7 @@ export class RemotesNode extends ViewNode {
return [new MessageNode(this.view, this, 'No remotes could be found')]; return [new MessageNode(this.view, this, 'No remotes could be found')];
} }
remotes.sort((a, b) => a.name.localeCompare(b.name));
remotes.sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }));
return [...Iterables.map(remotes, r => new RemoteNode(this.uri, this.view, this, r, this.repo))]; return [...Iterables.map(remotes, r => new RemoteNode(this.uri, this.view, this, r, this.repo))];
} }

+ 5
- 1
src/views/nodes/resultsFilesNode.ts View File

@ -46,7 +46,11 @@ export class ResultsFilesNode extends ViewNode {
children = (await root.getChildren()) as FileNode[]; children = (await root.getChildren()) as FileNode[];
} }
else { else {
children.sort((a, b) => a.priority - b.priority || a.label!.localeCompare(b.label!));
children.sort(
(a, b) =>
a.priority - b.priority ||
a.label!.localeCompare(b.label!, undefined, { numeric: true, sensitivity: 'base' })
);
} }
return children; return children;

+ 1
- 1
src/views/nodes/stashNode.ts View File

@ -42,7 +42,7 @@ export class StashNode extends ViewRefNode {
} }
const children = files.map(s => new StashFileNode(this.view, this, s, this.commit.toFileCommit(s))); const children = files.map(s => new StashFileNode(this.view, this, s, this.commit.toFileCommit(s)));
children.sort((a, b) => a.label!.localeCompare(b.label!));
children.sort((a, b) => a.label!.localeCompare(b.label!, undefined, { numeric: true, sensitivity: 'base' }));
return children; return children;
} }

+ 5
- 1
src/views/nodes/statusFilesNode.ts View File

@ -102,7 +102,11 @@ export class StatusFilesNode extends ViewNode {
children = (await root.getChildren()) as FileNode[]; children = (await root.getChildren()) as FileNode[];
} }
else { else {
children.sort((a, b) => a.priority - b.priority || a.label!.localeCompare(b.label!));
children.sort(
(a, b) =>
a.priority - b.priority ||
a.label!.localeCompare(b.label!, undefined, { numeric: true, sensitivity: 'base' })
);
} }
return children; return children;

+ 1
- 1
src/views/nodes/tagsNode.ts View File

@ -28,7 +28,7 @@ export class TagsNode extends ViewNode {
const tags = await this.repo.getTags(); const tags = await this.repo.getTags();
if (tags.length === 0) return [new MessageNode(this.view, this, 'No tags could be found.')]; if (tags.length === 0) return [new MessageNode(this.view, this, 'No tags could be found.')];
tags.sort((a, b) => a.name.localeCompare(b.name));
tags.sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }));
const tagNodes = tags.map(t => new TagNode(this.uri, this.view, this, t)); const tagNodes = tags.map(t => new TagNode(this.uri, this.view, this, t));
if (this.view.config.branches.layout === ViewBranchesLayout.List) return tagNodes; if (this.view.config.branches.layout === ViewBranchesLayout.List) return tagNodes;

Loading…
Cancel
Save