splitAt method
Splits this line into two at specified character index
.
This is an equivalent of inserting a line-break character at index
.
Implementation
LineNode splitAt(int index) {
assert(index == 0 || (index > 0 && index < length),
'Index is out of bounds. Index: $index. Actual node length: $length.');
final line = clone();
insertAfter(line);
if (index == length - 1) return line;
final split = lookup(index);
while (!split.node!.isLast) {
LeafNode child = last as LeafNode;
child.unlink();
line.addFirst(child);
}
LeafNode child = split.node as LeafNode;
line.addFirst(child.cutAt(split.offset)!);
return line;
}