optimize method

  1. @override
void optimize()
override

Optimizes this text node by merging it with adjacent nodes if they share the same style.

Implementation

@override
void optimize() {
  var node = this;
  if (!node.isFirst) {
    LeafNode mergeWith = node.previous;
    if (mergeWith.style == node.style) {
      mergeWith._value += node.value;
      node.unlink();
      node = mergeWith;
    }
  }
  if (!node.isLast) {
    LeafNode mergeWith = node.next;
    if (mergeWith.style == node.style) {
      node._value += mergeWith._value;
      mergeWith.unlink();
    }
  }
}