insert method
Inserts a string at a given position
.
If position
is null the currentPosition is taken.
Implementation
void insert(String text, {Position? position}) {
if (text.contains('\n')) {
insertLines(text.split('\n'), position: position);
} else {
position ??= currentPosition;
if (position.line >= lines.length) {
lines.add(text);
} else {
if (position.column == 0) {
lines[position.line] = text + lines[position.line];
} else {
final head = lines[position.line].substring(0, position.column);
final tail = lines[position.line].substring(position.column);
lines[position.line] = head + text + tail;
}
}
}
}