childAtPosition method

RenderEditableBox childAtPosition(
  1. TextPosition position
)
inherited

Returns child of this container at specified position in text.

The position parameter is expected to be relative to the node of this container.

Implementation

RenderEditableBox childAtPosition(TextPosition position) {
  assert(firstChild != null);

  final targetNode = node
      .lookup(math.min(position.offset, node.length), inclusive: true)
      .node;
  var targetChild = firstChild;
  while (targetChild != null) {
    if (targetChild.node == targetNode) {
      break;
    }
    targetChild = childAfter(targetChild);
  }
  assert(targetChild != null, 'No child at position $position');
  return targetChild!;
}