findParentsOfElement method

List<CNode> findParentsOfElement({
  1. required List<CNode> flatList,
  2. required CNode element,
})

Implementation

List<CNode> findParentsOfElement({
  required final List<CNode> flatList,
  required final CNode element,
}) {
  if (element.type == NType.scaffold) return [];
  assert(element.parentID != null, 'Parent ID cannot be null');
  final nodes = <CNode>[];
  final node = findParent(nodes: flatList, parentID: element.parentID!);
  nodes.add(node);
  for (var i = 0; i < 3; i++) {
    if (nodes.last.type == NType.scaffold) break;
    assert(nodes.last.parentID != null, 'Parent ID cannot be null');
    final parent =
        findParent(nodes: flatList, parentID: nodes.last.parentID!);
    nodes.add(parent);
  }
  return nodes;
}