resolveFragmentFromCursor function

Fragment? resolveFragmentFromCursor(
  1. FNode? currentNode,
  2. int offset
)

Resolves the actual Fragment from the cursor anchor node. The anchor may be a Fragment directly, or an InlineContainerNode whose child at offset (or first Fragment child) is the target.

Implementation

Fragment? resolveFragmentFromCursor(FNode? currentNode, int offset) {
  if (currentNode is Fragment) return currentNode;
  if (currentNode is InlineContainerNode) {
    final children = (currentNode as InlineContainerNode).getChildren();
    if (offset >= 0 && offset < children.length) {
      final child = children[offset];
      if (child is Fragment) return child;
    }
    for (final child in children) {
      if (child is Fragment) return child;
    }
  }
  return null;
}