findNodeAfterRecursive function
Implementation
InlineContainerNode? findNodeAfterRecursive(FNode container, FNode targetNode) {
final range = findDirectParent(container, targetNode);
if (range == null) {
return null; // No parent, no next node
}
final parentNode = range.node;
if (parentNode is InlineContainerNode) {
final siblings = (parentNode as InlineContainerNode).getChildren();
for (int i = 0; i < siblings.length; i++) {
if (siblings[i].id == targetNode.id) { // Found current node in parent's children
if (i < siblings.length - 1) { // Current node is not the last child, return next sibling
final nextSibling = siblings[i + 1];
if (nextSibling is InlineContainerNode) {
return nextSibling as InlineContainerNode;
}
} else { // Current node is the last child, recurse up the tree
return findNodeAfterRecursive(container, parentNode);
}
}
}
}
return null;
}