From 545bce5faaeb1fa4dfacf2573a5ef3061c7d15e6 Mon Sep 17 00:00:00 2001 From: MohamedHamou Date: Fri, 1 Feb 2019 11:34:54 +0100 Subject: [PATCH] Enhance setSelection of TreeContributor - generate all the sub paths of a given selected path --- src/contributors/TreeContributor.ts | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/contributors/TreeContributor.ts b/src/contributors/TreeContributor.ts index 7427639d..c0fdd8db 100644 --- a/src/contributors/TreeContributor.ts +++ b/src/contributors/TreeContributor.ts @@ -135,19 +135,19 @@ export class TreeContributor extends Contributor { const currentSelectedNodesPathsMap = new Map(); selectedNodesPathsList.forEach(path => { let id = ''; - path.forEach(node => { - id += node.fieldName + node.fieldValue ; - }); - currentSelectedNodesPathsMap.set(id, path); + for (let i = 1; i <= path.length; i++) { + id += path[path.length - i].fieldName + path[path.length - i].fieldValue; + currentSelectedNodesPathsMap.set(id, path.slice(path.length - i, path.length)); + } }); // Array of array to Map const olderSelectedNodesPathsMap = new Map(); this.selectedNodesPathsList.forEach(path => { let id = ''; - path.forEach(node => { - id += node.fieldName + node.fieldValue; - }); - olderSelectedNodesPathsMap.set(id, path); + for (let i = 1; i <= path.length; i++) { + id += path[path.length - i].fieldName + path[path.length - i].fieldValue; + olderSelectedNodesPathsMap.set(id, path.slice(path.length - i, path.length)); + } }); const mergedMap = new Map([...Array.from(currentSelectedNodesPathsMap.entries()), ...Array.from(olderSelectedNodesPathsMap.entries())]); @@ -161,13 +161,6 @@ export class TreeContributor extends Contributor { break; } } - // check if there is a path that is already included in a longer path - for (const k of Array.from(mergedMap.keys())) { - if (k.includes(key) && key !== k) { - addpath = false; - break; - } - } if (addpath) { selectedPaths.push(value); }