shiftRowsInRange method

void shiftRowsInRange({
  1. required int startLine,
  2. required int endLine,
  3. required int delta,
  4. required int maxLine,
  5. required int lineLength(
    1. int line
    ),
})

Implementation

void shiftRowsInRange({
  required int startLine,
  required int endLine,
  required int delta,
  required int maxLine,
  required int Function(int line) lineLength,
}) {
  if (_cursor.line >= startLine && _cursor.line <= endLine) {
    final nextLine = (_cursor.line + delta).clamp(0, maxLine);
    _cursor = TextPosition(
      line: nextLine,
      column: _cursor.column.clamp(0, lineLength(nextLine)),
    );
  }

  final currentSelection = _selection;
  if (currentSelection == null) {
    return;
  }

  _selection = TextSelection(
    base: _shiftPositionRowRange(
      currentSelection.base,
      startLine: startLine,
      endLine: endLine,
      delta: delta,
      maxLine: maxLine,
      lineLength: lineLength,
    ),
    extent: _shiftPositionRowRange(
      currentSelection.extent,
      startLine: startLine,
      endLine: endLine,
      delta: delta,
      maxLine: maxLine,
      lineLength: lineLength,
    ),
  );
}