From e1c2c743019c11eea29bb4cc1c301b1a13c8065e Mon Sep 17 00:00:00 2001 From: Marc Lasson Date: Mon, 14 Jan 2019 12:23:52 +0100 Subject: [PATCH] Fixes #626 - Avoid using object to implement Map 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. --- src/system/array.ts | 13 +++++++------ src/views/nodes/branchOrTagFolderNode.ts | 2 +- src/views/nodes/folderNode.ts | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/system/array.ts b/src/system/array.ts index 27f63f8..8446350 100644 --- a/src/system/array.ts +++ b/src/system/array.ts @@ -85,7 +85,7 @@ export namespace Arrays { value?: T; // parent?: IHierarchicalItem; - children: { [key: string]: IHierarchicalItem } | undefined; + children: Map> | undefined; descendants: T[] | undefined; } @@ -98,7 +98,7 @@ export namespace Arrays { const seed = { name: '', relativePath: '', - children: Object.create(null), + children: new Map(), descendants: [] }; @@ -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) { @@ -147,7 +148,7 @@ export namespace Arrays { ): IHierarchicalItem { 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)) { diff --git a/src/views/nodes/branchOrTagFolderNode.ts b/src/views/nodes/branchOrTagFolderNode.ts index a79988d..b877a42 100644 --- a/src/views/nodes/branchOrTagFolderNode.ts +++ b/src/views/nodes/branchOrTagFolderNode.ts @@ -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 = diff --git a/src/views/nodes/folderNode.ts b/src/views/nodes/folderNode.ts index b1fb513..2c839fe 100644 --- a/src/views/nodes/folderNode.ts +++ b/src/views/nodes/folderNode.ts @@ -41,7 +41,7 @@ export class FolderNode extends ViewNode { ); 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(