Bladeren bron

Consolidates case insensative comparisons

main
Eric Amodio 3 jaren geleden
bovenliggende
commit
98031210de
16 gewijzigde bestanden met toevoegingen van 43 en 65 verwijderingen
  1. +2
    -5
      src/api/actionRunners.ts
  2. +3
    -3
      src/git/models/branch.ts
  3. +3
    -7
      src/git/models/contributor.ts
  4. +2
    -1
      src/git/models/remote.ts
  5. +3
    -7
      src/git/models/tag.ts
  6. +1
    -1
      src/git/providers/localGitProvider.ts
  7. +17
    -6
      src/system/string.ts
  8. +2
    -3
      src/system/version.ts
  9. +1
    -5
      src/views/nodes/branchTrackingStatusFilesNode.ts
  10. +1
    -3
      src/views/nodes/commitNode.ts
  11. +2
    -2
      src/views/nodes/folderNode.ts
  12. +1
    -3
      src/views/nodes/mergeStatusNode.ts
  13. +2
    -6
      src/views/nodes/rebaseStatusNode.ts
  14. +1
    -5
      src/views/nodes/resultsFilesNode.ts
  15. +1
    -3
      src/views/nodes/stashNode.ts
  16. +1
    -5
      src/views/nodes/statusFilesNode.ts

+ 2
- 5
src/api/actionRunners.ts Bestand weergeven

@ -5,6 +5,7 @@ import { Config, configuration } from '../configuration';
import { ContextKeys, setContext } from '../constants';
import { Container } from '../container';
import { getQuickPickIgnoreFocusOut } from '../quickpicks';
import { Strings } from '../system';
import type { Action, ActionContext, ActionRunner } from './gitlens';
type Actions = ActionContext['type'];
@ -255,11 +256,7 @@ export class ActionRunners implements Disposable {
if (runners.length > 1 || runners.every(r => r.type !== ActionRunnerType.BuiltIn)) {
const items: (ActionRunnerQuickPickItem | NoActionRunnersQuickPickItem)[] = runners
// .filter(r => r.when(context))
.sort(
(a, b) =>
a.order - b.order ||
a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }),
)
.sort((a, b) => a.order - b.order || Strings.sortCompare(a.name, b.name))
.map(r => new ActionRunnerQuickPickItem(r, context));
if (items.length === 0) {

+ 3
- 3
src/git/models/branch.ts Bestand weergeven

@ -2,7 +2,7 @@
import { BranchSorting, configuration, DateStyle } from '../../configuration';
import { Starred, WorkspaceState } from '../../constants';
import { Container } from '../../container';
import { Dates, debug, memoize } from '../../system';
import { Dates, debug, memoize, Strings } from '../../system';
import { GitRemote, GitRevision } from '../git';
import { GitBranchReference, GitReference, PullRequest, PullRequestState } from './models';
import { GitStatus } from './status';
@ -78,7 +78,7 @@ export class GitBranch implements GitBranchReference {
(a.name === 'master' ? -1 : 1) - (b.name === 'master' ? -1 : 1) ||
(a.name === 'develop' ? -1 : 1) - (b.name === 'develop' ? -1 : 1) ||
(b.remote ? -1 : 1) - (a.remote ? -1 : 1) ||
a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }),
Strings.sortCompare(a.name, b.name),
);
case BranchSorting.NameDesc:
return branches.sort(
@ -92,7 +92,7 @@ export class GitBranch implements GitBranchReference {
(a.name === 'master' ? -1 : 1) - (b.name === 'master' ? -1 : 1) ||
(a.name === 'develop' ? -1 : 1) - (b.name === 'develop' ? -1 : 1) ||
(b.remote ? -1 : 1) - (a.remote ? -1 : 1) ||
b.name.localeCompare(a.name, undefined, { numeric: true, sensitivity: 'base' }),
Strings.sortCompare(b.name, a.name),
);
case BranchSorting.DateDesc:
default:

+ 3
- 7
src/git/models/contributor.ts Bestand weergeven

@ -2,7 +2,7 @@
import { Uri } from 'vscode';
import { getAvatarUri } from '../../avatars';
import { configuration, ContributorSorting, GravatarDefaultStyle } from '../../configuration';
import { Dates, memoize } from '../../system';
import { Dates, memoize, Strings } from '../../system';
export interface ContributorSortOptions {
current?: true;
@ -41,15 +41,11 @@ export class GitContributor {
);
case ContributorSorting.NameAsc:
return contributors.sort(
(a, b) =>
(a.current ? -1 : 1) - (b.current ? -1 : 1) ||
a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }),
(a, b) => (a.current ? -1 : 1) - (b.current ? -1 : 1) || Strings.sortCompare(a.name, b.name),
);
case ContributorSorting.NameDesc:
return contributors.sort(
(a, b) =>
(a.current ? -1 : 1) - (b.current ? -1 : 1) ||
b.name.localeCompare(a.name, undefined, { numeric: true, sensitivity: 'base' }),
(a, b) => (a.current ? -1 : 1) - (b.current ? -1 : 1) || Strings.sortCompare(b.name, a.name),
);
case ContributorSorting.CountDesc:
default:

+ 2
- 1
src/git/models/remote.ts Bestand weergeven

@ -1,6 +1,7 @@
'use strict';
import { WorkspaceState } from '../../constants';
import { Container } from '../../container';
import { Strings } from '../../system';
import { RemoteProvider, RichRemoteProvider } from '../remotes/factory';
export const enum GitRemoteType {
@ -43,7 +44,7 @@ export class GitRemote
(a, b) =>
(a.default ? -1 : 1) - (b.default ? -1 : 1) ||
(a.name === 'origin' ? -1 : 1) - (b.name === 'origin' ? -1 : 1) ||
a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }),
Strings.sortCompare(a.name, b.name),
);
}

+ 3
- 7
src/git/models/tag.ts Bestand weergeven

@ -1,6 +1,6 @@
'use strict';
import { configuration, DateStyle, TagSorting } from '../../configuration';
import { Dates, memoize } from '../../system';
import { Dates, memoize, Strings } from '../../system';
import { GitReference, GitTagReference } from './models';
export const TagDateFormatting = {
@ -34,13 +34,9 @@ export class GitTag implements GitTagReference {
case TagSorting.DateAsc:
return tags.sort((a, b) => a.date.getTime() - b.date.getTime());
case TagSorting.NameAsc:
return tags.sort((a, b) =>
a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }),
);
return tags.sort((a, b) => Strings.sortCompare(a.name, b.name));
case TagSorting.NameDesc:
return tags.sort((a, b) =>
b.name.localeCompare(a.name, undefined, { numeric: true, sensitivity: 'base' }),
);
return tags.sort((a, b) => Strings.sortCompare(b.name, a.name));
case TagSorting.DateDesc:
default:
return tags.sort((a, b) => b.date.getTime() - a.date.getTime());

+ 1
- 1
src/git/providers/localGitProvider.ts Bestand weergeven

@ -3070,7 +3070,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
return;
}
if (path.toLowerCase() === resolvedPath.toLowerCase()) {
if (Strings.equalsIgnoreCase(path, resolvedPath)) {
Logger.debug(cc, `No symlink detected; repoPath=${repoPath}`);
resolve(repoPath);
return;

+ 17
- 6
src/system/string.ts Bestand weergeven

@ -22,6 +22,23 @@ export const enum CharCode {
z = 122,
}
const compareCollator = new Intl.Collator(undefined, { sensitivity: 'accent' });
export function compareIgnoreCase(a: string, b: string): 0 | -1 | 1 {
const result = compareCollator.compare(a, b);
// Intl.Collator.compare isn't guaranteed to always return 1 or -1 on all platforms so normalize it
return result === 0 ? 0 : result > 0 ? 1 : -1;
}
export function equalsIgnoreCase(a: string | null | undefined, b: string | null | undefined): boolean {
// Treat `null` & `undefined` as equivalent
if (a == null && b == null) return true;
if (a == null || b == null) return false;
return compareIgnoreCase(a, b) === 0;
}
export const sortCollator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
export const sortCompare = sortCollator.compare;
export function compareSubstring(
a: string,
b: string,
@ -112,12 +129,6 @@ export function escapeMarkdown(s: string, options: { quoted?: boolean } = {}): s
return s.replace(markdownQuotedRegex, '\t\n> ');
}
export function equalsIgnoreCase(a: string | null | undefined, b: string | null | undefined): boolean {
if (a == null && b == null) return true;
if (a == null || b == null) return false;
return a.localeCompare(b, undefined, { sensitivity: 'accent' }) === 0;
}
export function escapeRegex(s: string) {
return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}

+ 2
- 3
src/system/version.ts Bestand weergeven

@ -1,4 +1,5 @@
'use strict';
import { compareIgnoreCase } from './string';
declare type VersionComparisonResult = -1 | 0 | 1;
@ -29,9 +30,7 @@ export function compare(v1: string | Version, v2: string | Version): VersionComp
if (v1.pre === undefined && v2.pre !== undefined) return 1;
if (v1.pre !== undefined && v2.pre === undefined) return -1;
if (v1.pre !== undefined && v2.pre !== undefined) {
return v1.pre.localeCompare(v2.pre) as VersionComparisonResult;
}
if (v1.pre !== undefined && v2.pre !== undefined) return compareIgnoreCase(v1.pre, v2.pre);
return 0;
}

+ 1
- 5
src/views/nodes/branchTrackingStatusFilesNode.ts Bestand weergeven

@ -91,11 +91,7 @@ export class BranchTrackingStatusFilesNode extends ViewNode {
const root = new FolderNode(this.view, this, this.repoPath, '', hierarchy, false);
children = root.getChildren() as FileNode[];
} else {
children.sort(
(a, b) =>
a.priority - b.priority ||
a.label!.localeCompare(b.label!, undefined, { numeric: true, sensitivity: 'base' }),
);
children.sort((a, b) => a.priority - b.priority || Strings.sortCompare(a.label!, b.label!));
}
return children;

+ 1
- 3
src/views/nodes/commitNode.ts Bestand weergeven

@ -63,9 +63,7 @@ export class CommitNode extends ViewRefNode
const root = new FolderNode(this.view, this, this.repoPath, '', hierarchy);
children = root.getChildren() as FileNode[];
} else {
(children as FileNode[]).sort((a, b) =>
a.label!.localeCompare(b.label!, undefined, { numeric: true, sensitivity: 'base' }),
);
(children as FileNode[]).sort((a, b) => Strings.sortCompare(a.label!, b.label!));
}
if (!(this.view instanceof TagsView) && !(this.view instanceof FileHistoryView)) {

+ 2
- 2
src/views/nodes/folderNode.ts Bestand weergeven

@ -2,7 +2,7 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ViewFilesLayout, ViewsFilesConfig } from '../../configuration';
import { GitUri } from '../../git/gitUri';
import { Arrays } from '../../system';
import { Arrays, Strings } from '../../system';
import { FileHistoryView } from '../fileHistoryView';
import { StashesView } from '../stashesView';
import { ViewsWithCommits } from '../viewBase';
@ -77,7 +77,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!, undefined, { numeric: true, sensitivity: 'base' })
Strings.sortCompare(a.label!, b.label!)
);
});

+ 1
- 3
src/views/nodes/mergeStatusNode.ts Bestand weergeven

@ -55,9 +55,7 @@ export class MergeStatusNode extends ViewNode {
const root = new FolderNode(this.view, this, this.repoPath, '', hierarchy);
children = root.getChildren() as FileNode[];
} else {
children.sort((a, b) =>
a.label!.localeCompare(b.label!, undefined, { numeric: true, sensitivity: 'base' }),
);
children.sort((a, b) => Strings.sortCompare(a.label!, b.label!));
}
return children;

+ 2
- 6
src/views/nodes/rebaseStatusNode.ts Bestand weergeven

@ -72,9 +72,7 @@ export class RebaseStatusNode extends ViewNode {
const root = new FolderNode(this.view, this, this.repoPath, '', hierarchy);
children = root.getChildren() as FileNode[];
} else {
children.sort((a, b) =>
a.label!.localeCompare(b.label!, undefined, { numeric: true, sensitivity: 'base' }),
);
children.sort((a, b) => Strings.sortCompare(a.label!, b.label!));
}
const commit = await this.view.container.git.getCommit(
@ -191,9 +189,7 @@ export class RebaseCommitNode extends ViewRefNode
const root = new FolderNode(this.view, this, this.repoPath, '', hierarchy);
children = root.getChildren() as FileNode[];
} else {
children.sort((a, b) =>
a.label!.localeCompare(b.label!, undefined, { numeric: true, sensitivity: 'base' }),
);
children.sort((a, b) => Strings.sortCompare(a.label!, b.label!));
}
return children;

+ 1
- 5
src/views/nodes/resultsFilesNode.ts Bestand weergeven

@ -85,11 +85,7 @@ export class ResultsFilesNode extends ViewNode {
const root = new FolderNode(this.view, this, this.repoPath, '', hierarchy);
children = root.getChildren() as FileNode[];
} else {
children.sort(
(a, b) =>
a.priority - b.priority ||
a.label!.localeCompare(b.label!, undefined, { numeric: true, sensitivity: 'base' }),
);
children.sort((a, b) => a.priority - b.priority || Strings.sortCompare(a.label!, b.label!));
}
return children;

+ 1
- 3
src/views/nodes/stashNode.ts Bestand weergeven

@ -49,9 +49,7 @@ export class StashNode extends ViewRefNode
const root = new FolderNode(this.view, this, this.repoPath, '', hierarchy);
children = root.getChildren() as FileNode[];
} else {
children.sort((a, b) =>
a.label!.localeCompare(b.label!, undefined, { numeric: true, sensitivity: 'base' }),
);
children.sort((a, b) => Strings.sortCompare(a.label!, b.label!));
}
return children;
}

+ 1
- 5
src/views/nodes/statusFilesNode.ts Bestand weergeven

@ -118,11 +118,7 @@ export class StatusFilesNode extends ViewNode {
const root = new FolderNode(this.view, this, repoPath, '', hierarchy, true);
children = root.getChildren() as FileNode[];
} else {
children.sort(
(a, b) =>
a.priority - b.priority ||
a.label!.localeCompare(b.label!, undefined, { numeric: true, sensitivity: 'base' }),
);
children.sort((a, b) => a.priority - b.priority || Strings.sortCompare(a.label!, b.label!));
}
return children;

Laden…
Annuleren
Opslaan