adjust method
Adjust this text node by merging it with adjacent nodes if they share the same style.
Implementation
@override
void adjust() {
if (this is Embed) {
// Embed nodes cannot be merged with text nor other embeds (in fact,
// there could be no two adjacent embeds on the same line since an
// embed occupies an entire line).
return;
}
// This is a text node and it can only be merged with other text nodes.
var node = this as NodeText;
// Merging it with previous node if style is the same.
final prev = node.previous;
if (!node.isFirst && prev is NodeText && prev.style == node.style) {
prev._value = prev.value + node.value;
node.unlink();
node = prev;
}
// Merging it with next node if style is the same.
final next = node.next;
if (!node.isLast && next is NodeText && next.style == node.style) {
node._value = node.value + next.value;
next.unlink();
}
}