insertLines method
Inserts a string list at a given position
.
If position
is null the currentPosition is taken.
Implementation
void insertLines(List<String> textLines, {Position? position}) {
position ??= currentPosition;
if (position.line >= textLines.length) {
lines += textLines;
} else if (position.column == 0) {
lines.insertAll(position.line, textLines);
} else {
final restLine = lines[position.line].substring(position.column);
lines[position.line] =
lines[position.line].substring(0, position.column) + textLines[0];
lines.insert(position.line + 1, restLine);
lines.insertAll(position.line + 1, textLines.sublist(1));
}
}