getFirstDescendant method

LexicalNode? getFirstDescendant()

The first leaf under this element, or null when it holds nothing.

"Leaf" as the tree means it: the walk descends through elements until it reaches something that is not one, so a paragraph nested three lists deep answers with its text node rather than with the list.

Implementation

LexicalNode? getFirstDescendant() {
  var node = getFirstChild();
  while (node is ElementNode) {
    final child = node.getFirstChild();
    if (child == null) break;
    node = child;
  }
  return node;
}