splitAt method
Splits this leaf node at index
and returns new node.
If this is the last node in its list and index
equals this node's
length then this method returns null
as there is nothing left to split.
If there is another leaf node after this one and index
equals this
node's length then the next leaf node is returned.
If index
equals to 0
then this node itself is returned unchanged.
In case a new node is actually split from this one, it inherits this node's style.
Implementation
Leaf? splitAt(int index) {
assert(index >= 0 && index <= length);
if (index == 0) {
return this;
}
if (index == length) {
return isLast ? null : next as Leaf?;
}
assert(this is Text);
final text = _value as String;
_value = text.substring(0, index);
final split = Leaf(text.substring(index))..applyStyle(style);
insertAfter(split);
return split;
}