deleteLinesAtSelections method
Deletes every line touched by an active cursor or selection.
Implementation
bool deleteLinesAtSelections() {
return _runEditFrame(() {
_beginHistoryAction(
_TextAreaHistoryAction.deleteForward,
breakChain: true,
);
_refreshDocumentSnapshot();
final lines = _selectedLineIndexes().toList()
..sort((a, b) => b.compareTo(a));
if (lines.isEmpty) return false;
final graphemes = _document.flattenWithNewlines();
var next = selections;
var changed = false;
for (final line in lines) {
final start = _document.lineStartOffset(line);
final end = _document.lineEndOffset(line, includeTrailingNewline: true);
if (start == end) continue;
if (!changed) _recordUndoSnapshot();
graphemes.replaceRange(start, end, const <String>[]);
next = next.applyDeletion(startOffset: start, endOffset: end);
changed = true;
}
if (!changed) return false;
_replaceText(graphemes.isEmpty ? '' : graphemes.join());
setSelections(next);
return true;
});
}