absorbNode method

  1. @override
bool absorbNode(
  1. Node? other
)
override

Implementation

@override
bool absorbNode(Node? other) {
  if (other == null) return false;

  if (node is Text) {
    if (other is Text) {
      node!.text = (node!.text ?? '') + other.text!;
      other.text = '';
      return true;
    } else if (other is Element) {
      node!.text = (node!.text ?? '') + other.text!;
      other.nodes.clear();
      return true;
    }
  } else if (node is Element) {
    if (other is Element) {
      if (other.nodes.isEmpty) {
        return true;
      }
      nodeAsElement!.nodes.addAll(other.nodes);
      other.nodes.clear();
      return true;
    } else if (other is Text) {
      other.remove();
      nodeAsElement!.append(other);
      return true;
    }
  }

  return false;
}