findNodeBeforeRecursive function
Implementation
InlineContainerNode? findNodeBeforeRecursive(FNode container, FNode targetNode) {
if (container is InlineContainerNode) {
final children = (container as InlineContainerNode).getChildren();
for (int i = 0; i < children.length; i++) {
if (children[i].id == targetNode.id) { // Found target, return previous if exists
if (i > 0 && children[i - 1] is InlineContainerNode) {
return children[i - 1] as InlineContainerNode;
}
return null;
}
// Search recursively in children
final result = findNodeBeforeRecursive(children[i], targetNode);
if (result != null) {
return result;
}
}
}
return null;
}