From 84f7ee93c61f8df35bb2414efdcbe2bb24ab8513 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 16 Nov 2018 11:01:40 -0500 Subject: [PATCH] Closes #547 - Adds natural sorting to branches, tags, and files --- src/quickpicks/branchesAndTagsQuickPick.ts | 8 ++++++-- src/quickpicks/repoStatusQuickPick.ts | 4 +++- src/views/nodes/branchesNode.ts | 7 +++---- src/views/nodes/commitNode.ts | 4 +++- src/views/nodes/folderNode.ts | 2 +- src/views/nodes/remoteNode.ts | 12 +++++------- src/views/nodes/remotesNode.ts | 2 +- src/views/nodes/resultsFilesNode.ts | 6 +++++- src/views/nodes/stashNode.ts | 2 +- src/views/nodes/statusFilesNode.ts | 6 +++++- src/views/nodes/tagsNode.ts | 2 +- 11 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/quickpicks/branchesAndTagsQuickPick.ts b/src/quickpicks/branchesAndTagsQuickPick.ts index e723e61..e9407b5 100644 --- a/src/quickpicks/branchesAndTagsQuickPick.ts +++ b/src/quickpicks/branchesAndTagsQuickPick.ts @@ -265,7 +265,11 @@ export class BranchesAndTagsQuickPick { const filter = 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) { if (filter !== undefined && !filter(b)) continue; @@ -276,7 +280,7 @@ export class BranchesAndTagsQuickPick { if (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) { if (filter !== undefined && !filter(t)) continue; diff --git a/src/quickpicks/repoStatusQuickPick.ts b/src/quickpicks/repoStatusQuickPick.ts index ddf821d..d4a890b 100644 --- a/src/quickpicks/repoStatusQuickPick.ts +++ b/src/quickpicks/repoStatusQuickPick.ts @@ -224,7 +224,9 @@ export class RepoStatusQuickPick { ((a as OpenStatusFileCommandQuickPickItem).status.staged ? -1 : 1) - ((b as OpenStatusFileCommandQuickPickItem).status.staged ? -1 : 1) || (a as OpenStatusFileCommandQuickPickItem).status.fileName.localeCompare( - (b as OpenStatusFileCommandQuickPickItem).status.fileName + (b as OpenStatusFileCommandQuickPickItem).status.fileName, + undefined, + { numeric: true, sensitivity: 'base' } ) ); diff --git a/src/views/nodes/branchesNode.ts b/src/views/nodes/branchesNode.ts index 19708a7..6b13969 100644 --- a/src/views/nodes/branchesNode.ts +++ b/src/views/nodes/branchesNode.ts @@ -30,13 +30,12 @@ export class BranchesNode extends ViewNode { const branches = await this.repo.getBranches(); 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 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; diff --git a/src/views/nodes/commitNode.ts b/src/views/nodes/commitNode.ts index e7b49ef..b0fcc68 100644 --- a/src/views/nodes/commitNode.ts +++ b/src/views/nodes/commitNode.ts @@ -48,7 +48,9 @@ export class CommitNode extends ViewRefNode { children = (await root.getChildren()) as FileNode[]; } 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; } diff --git a/src/views/nodes/folderNode.ts b/src/views/nodes/folderNode.ts index de7070c..45f3fc4 100644 --- a/src/views/nodes/folderNode.ts +++ b/src/views/nodes/folderNode.ts @@ -61,7 +61,7 @@ export class FolderNode extends ViewNode { return ( (a instanceof FolderNode ? -1 : 1) - (b instanceof FolderNode ? -1 : 1) || a.priority - b.priority || - a.label!.localeCompare(b.label!) + a.label!.localeCompare(b.label!, undefined, { numeric: true, sensitivity: 'base' }) ); }); diff --git a/src/views/nodes/remoteNode.ts b/src/views/nodes/remoteNode.ts index 915b2f3..cf311c3 100644 --- a/src/views/nodes/remoteNode.ts +++ b/src/views/nodes/remoteNode.ts @@ -29,16 +29,14 @@ export class RemoteNode extends ViewNode { const branches = await this.repo.getBranches(); 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 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; diff --git a/src/views/nodes/remotesNode.ts b/src/views/nodes/remotesNode.ts index bb326a3..4997e1e 100644 --- a/src/views/nodes/remotesNode.ts +++ b/src/views/nodes/remotesNode.ts @@ -28,7 +28,7 @@ export class RemotesNode extends ViewNode { 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))]; } diff --git a/src/views/nodes/resultsFilesNode.ts b/src/views/nodes/resultsFilesNode.ts index 13f614f..550d3cf 100644 --- a/src/views/nodes/resultsFilesNode.ts +++ b/src/views/nodes/resultsFilesNode.ts @@ -46,7 +46,11 @@ export class ResultsFilesNode extends ViewNode { children = (await root.getChildren()) as FileNode[]; } 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; diff --git a/src/views/nodes/stashNode.ts b/src/views/nodes/stashNode.ts index 6b05cb1..1b85b77 100644 --- a/src/views/nodes/stashNode.ts +++ b/src/views/nodes/stashNode.ts @@ -42,7 +42,7 @@ export class StashNode extends ViewRefNode { } 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; } diff --git a/src/views/nodes/statusFilesNode.ts b/src/views/nodes/statusFilesNode.ts index 340d431..21abb29 100644 --- a/src/views/nodes/statusFilesNode.ts +++ b/src/views/nodes/statusFilesNode.ts @@ -102,7 +102,11 @@ export class StatusFilesNode extends ViewNode { children = (await root.getChildren()) as FileNode[]; } 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; diff --git a/src/views/nodes/tagsNode.ts b/src/views/nodes/tagsNode.ts index 272c397..8ddac4e 100644 --- a/src/views/nodes/tagsNode.ts +++ b/src/views/nodes/tagsNode.ts @@ -28,7 +28,7 @@ export class TagsNode extends ViewNode { const tags = await this.repo.getTags(); 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)); if (this.view.config.branches.layout === ViewBranchesLayout.List) return tagNodes;