handleInsertItemsEvent method

  1. @visibleForTesting
void handleInsertItemsEvent(
  1. NodeInsertEvent<INode> event
)

Implementation

@visibleForTesting
void handleInsertItemsEvent(NodeInsertEvent<INode> event) {
  for (final node in event.items) {
    if (animatedListStateController.containsKey(node.path)) continue;

    if (node.isRoot || node.parent?.isRoot == true) {
      if (!(node.root as ITreeNode<Data>).isExpanded) {
        expansionBehaviourController.expandNode(node.root as ITreeNode<Data>);
      } else {
        animatedListStateController.insertAll(
            animatedListStateController.showRootNode
                ? event.index + 1
                : event.index,
            List.from(event.items));
      }
      if (focusToNewNode) {
        expansionBehaviourController.scrollToLastVisibleChild(node.root);
      }
    } else {
      final parentIndex = animatedListStateController.list
          .indexWhere((element) => element.key == node.parent?.key);
      if (parentIndex < 0) continue;

      final parentNode = animatedListStateController.list[parentIndex];

      if (!parentNode.isExpanded) {
        expansionBehaviourController.expandNode(parentNode);
      } else {
        animatedListStateController.insertAll(
            parentIndex + 1 + event.index, List.from(event.items));
      }
      if (focusToNewNode) {
        expansionBehaviourController.scrollToLastVisibleChild(parentNode);
      }
    }
  }
}