findDirectParent function

FNodeRange? findDirectParent(
  1. FNode root,
  2. FNode target
)

Implementation

FNodeRange? findDirectParent(FNode root, FNode target) {
  if (root is InlineContainerNode) {
    for (final child in (root as InlineContainerNode).getChildren()) {
      if (child.id == target.id) return FNodeRange(node: root, parent: null);
      if (child is InlineContainerNode) {
        final found = findDirectParent(child, target);
        if (found != null) {
          return FNodeRange(
            node: found.node,
            parent: found.parent ?? root,
          );
        }
      }
    }
  }
  return null;
}