Skip to content

Commit

Permalink
Fixes #626 - Avoid using object to implement Map
Browse files Browse the repository at this point in the history
This commit fixes a bug occurring with branch names which are parsable
integers.

They were always shown first in the list of branches (even if they are
not starred) because the chrome implementation does not respect the
insertion order for keys that happen to be parseable integers.
  • Loading branch information
mlasson authored and eamodio committed Jan 23, 2019
1 parent cabd217 commit e1c2c74
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/system/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export namespace Arrays {
value?: T;

// parent?: IHierarchicalItem<T>;
children: { [key: string]: IHierarchicalItem<T> } | undefined;
children: Map<string, IHierarchicalItem<T>> | undefined;
descendants: T[] | undefined;
}

Expand All @@ -98,7 +98,7 @@ export namespace Arrays {
const seed = {
name: '',
relativePath: '',
children: Object.create(null),
children: new Map(),
descendants: []
};

Expand All @@ -110,18 +110,19 @@ export namespace Arrays {
relativePath = joinPath(relativePath, folderName);

if (folder.children === undefined) {
folder.children = Object.create(null);
folder.children = new Map();
}

let f = folder.children![folderName];
let f = folder.children!.get(folderName);
if (f === undefined) {
folder.children![folderName] = f = {
f = {
name: folderName,
relativePath: relativePath,
// parent: folder,
children: undefined,
descendants: undefined
};
folder.children.set(folderName, f);
}

if (folder.descendants === undefined) {
Expand All @@ -147,7 +148,7 @@ export namespace Arrays {
): IHierarchicalItem<T> {
if (root.children === undefined) return root;

const children = [...Objects.values(root.children)];
const children = [...root.children.values()];

// // Attempts less nesting but duplicate roots
// if (!isRoot && children.every(c => c.value === undefined)) {
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/branchOrTagFolderNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class BranchOrTagFolderNode extends ViewNode {

const children: (BranchOrTagFolderNode | BranchNode | TagNode)[] = [];

for (const folder of Objects.values(this.root.children)) {
for (const folder of this.root.children.values()) {
if (folder.value === undefined) {
// If the folder contains the current branch, expand it by default
const expanded =
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/folderNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class FolderNode extends ViewNode<ViewWithFiles> {
);
if (nesting !== ViewFilesLayout.List) {
children = [];
for (const folder of Objects.values(this.root.children)) {
for (const folder of this.root.children.values()) {
if (folder.value === undefined) {
children.push(
new FolderNode(
Expand Down

0 comments on commit e1c2c74

Please sign in to comment.