From 9e738c43666c90b489f669dca2ca2d834a16f41b Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Mon, 22 Nov 2021 07:56:22 +0200 Subject: [PATCH] fix(Hierarchy Note): :bug: Handle top item --- src/main.ts | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/main.ts b/src/main.ts index 7feb2654..f2b697cf 100644 --- a/src/main.ts +++ b/src/main.ts @@ -487,30 +487,37 @@ export default class BCPlugin extends Plugin { const { HNUpField } = settings; const upFields = getFields(userHiers, "up"); - hierarchyNotesArr.forEach((hnItem) => { - if (hnItem.parentNote === null) return; - + hierarchyNotesArr.forEach((hnItem, i) => { const upField = hnItem.field ?? (HNUpField || upFields[0]); const downField = getOppFields(userHiers, upField)[0] ?? `${upField}`; - const aUp = { - dir: "up", - field: upField, - }; - //@ts-ignore - addNodesIfNot(mainG, [hnItem.currNote, hnItem.parentNote], aUp); - //@ts-ignore - addEdgeIfNot(mainG, hnItem.currNote, hnItem.parentNote, aUp); - - const aDown = { - dir: "down", - field: downField, - }; - //@ts-ignore - addNodesIfNot(mainG, [hnItem.parentNote, hnItem.currNote], aDown); - //@ts-ignore - addEdgeIfNot(mainG, hnItem.parentNote, hnItem.currNote, aDown); + if (hnItem.parentNote === null) { + const s = hnItem.currNote; + const t = hierarchyNotesArr[i + 1].currNote; + //@ts-ignore + addNodesIfNot(mainG, [s, t], { dir: "down", field: downField }); + //@ts-ignore + addEdgeIfNot(mainG, s, t, { dir: "down", field: downField }); + } else { + const aUp = { + dir: "up", + field: upField, + }; + //@ts-ignore + addNodesIfNot(mainG, [hnItem.currNote, hnItem.parentNote], aUp); + //@ts-ignore + addEdgeIfNot(mainG, hnItem.currNote, hnItem.parentNote, aUp); + + const aDown = { + dir: "down", + field: downField, + }; + //@ts-ignore + addNodesIfNot(mainG, [hnItem.parentNote, hnItem.currNote], aDown); + //@ts-ignore + addEdgeIfNot(mainG, hnItem.parentNote, hnItem.currNote, aDown); + } }); }