optimize method
Optimizes this text node by merging it with adjacent nodes if they share the same style.
Implementation
@override
void optimize() {
LeafNode node = this;
if (!node.isFirst) {
LeafNode mergeWith = node.previous as LeafNode;
if (mergeWith.style == node.style) {
mergeWith._value += node.value;
node.unlink();
node = mergeWith;
}
}
if (!node.isLast) {
LeafNode mergeWith = node.next as LeafNode;
if (mergeWith.style == node.style) {
node._value += mergeWith._value;
mergeWith.unlink();
}
}
}