mergeNearNodes method

DOMNodeMapping<T>? mergeNearNodes(
  1. DOMNode domNode1,
  2. DOMNode domNode2, {
  3. bool onlyCompatibles = false,
})

Implementation

DOMNodeMapping<T>? mergeNearNodes(DOMNode domNode1, DOMNode domNode2,
    {bool onlyCompatibles = false}) {
  if (onlyCompatibles && !domNode1.isCompatibleForMerge(domNode2)) {
    return null;
  }

  var nodeRuntime1 = domNode1.runtime;
  var nodeRuntime2 = domNode2.runtime;

  if (domNode1.isNextNode(domNode2)) {
    if (domNode1.merge(domNode2) &&
        nodeRuntime1.mergeNode(nodeRuntime2.node)) {
      unmap(domNode2, nodeRuntime2.node);
      return DOMNodeMapping(this, domNode1, nodeRuntime1.node);
    }
  } else if (domNode1.isPreviousNode(domNode2)) {
    if (domNode2.merge(domNode1) &&
        nodeRuntime2.mergeNode(nodeRuntime1.node)) {
      unmap(domNode1, nodeRuntime1.node);
      return DOMNodeMapping(this, domNode2, nodeRuntime2.node);
    }
  }

  return null;
}