optimize method
Optimize this node within parent.
Subclasses should override this method to perform necessary optimizations.
Implementation
@override
void optimize() {
if (isEmpty) {
final sibling = previous;
unlink();
if (sibling != null) sibling.optimize();
return;
}
BlockNode block = this;
if (!block.isFirst && block.previous is BlockNode) {
BlockNode prev = block.previous as BlockNode;
if (prev.style == block.style) {
block.moveChildren(prev);
block.unlink();
block = prev;
}
}
if (!block.isLast && block.next is BlockNode) {
BlockNode nextBlock = block.next as BlockNode;
if (nextBlock.style == block.style) {
nextBlock.moveChildren(block);
nextBlock.unlink();
}
}
}