deleteFromTo method
Deletes the text between the positions start
and end
.
If start
is null the current position is taken.
Implementation
void deleteFromTo({Position? start, required Position end}) {
start ??= currentPosition;
if (start.isBelow(end)) {
Position temp;
temp = start;
start = end;
end = temp;
}
if (start.line == end.line) {
lines[start.line] = lines[start.line].substring(0, start.column) +
lines[start.line].substring(end.column);
} else {
var ixStart = start.line;
var ixEnd = end.line + 1;
if (start.column > 0) {
lines[start.line] = lines[start.line].substring(0, start.column);
ixStart++;
}
if (end.column > 0) {
lines[end.line] = lines[end.line].substring(end.column);
ixEnd--;
}
if (ixStart < ixEnd) {
lines.removeRange(ixStart, ixEnd);
}
}
if (currentRegion.end.line > lines.length) {
currentRegion.end.set(lines.length, 0);
}
}