scrollRect method

void scrollRect(
  1. int left,
  2. int right,
  3. int rowTop,
  4. int rowBottom,
  5. int n, [
  6. StyleId style = StyleId.base,
])

Moves the content of the rectangle columns [left, right) x rows [rowTop, rowBottom) up by n rows (down when negative), like scrollRows but for a scroll view that doesn't span the whole width (a side panel, a list inside a border). Wide glyphs cut by the rectangle's left/right edges are broken (both halves blanked) first. The move is recorded; the presenter replays it with DECSLRM margins where the terminal has them.

Implementation

void scrollRect(
  int left,
  int right,
  int rowTop,
  int rowBottom,
  int n, [
  StyleId style = StyleId.base,
]) {
  final x0 = left < 0 ? 0 : left;
  final x1 = right > width ? width : right;
  final top = rowTop < 0 ? 0 : rowTop;
  final bottom = rowBottom > height ? height : rowBottom;
  if (x0 == 0 && x1 == width) {
    scrollRows(top, bottom, n, style);
    return;
  }
  if (n == 0 || top >= bottom || x0 >= x1) {
    return;
  }
  final w = width;
  final k = n.abs();
  if (images.isNotEmpty) {
    _scrollImages(x0, x1, top, bottom, n);
  }
  for (var y = top; y < bottom; y++) {
    _breakEdge(y, x0);
    _breakEdge(y, x1);
  }
  if (k >= bottom - top) {
    for (var y = top; y < bottom; y++) {
      fillU32(cells, y * w + x0, y * w + x1, kBlank);
      fillU32(styles, y * w + x0, y * w + x1, style.value);
      markDirty(y, x0, x1);
    }
    return;
  }
  // the damage inside the rectangle moves with its cells (each row's
  // read before it is written over: rows in the order they are
  // written), that beside it stays, and the exposed rows are damaged
  if (n > 0) {
    for (var y = top; y < bottom - k; y++) {
      cells.setRange(y * w + x0, y * w + x1, cells, (y + k) * w + x0);
      styles.setRange(y * w + x0, y * w + x1, styles, (y + k) * w + x0);
      _moveDamage(y, y + k, x0, x1);
    }
    for (var y = bottom - k; y < bottom; y++) {
      fillU32(cells, y * w + x0, y * w + x1, kBlank);
      fillU32(styles, y * w + x0, y * w + x1, style.value);
      _moveDamage(y, -1, x0, x1);
    }
  } else {
    for (var y = bottom - 1; y >= top + k; y--) {
      cells.setRange(y * w + x0, y * w + x1, cells, (y - k) * w + x0);
      styles.setRange(y * w + x0, y * w + x1, styles, (y - k) * w + x0);
      _moveDamage(y, y - k, x0, x1);
    }
    for (var y = top; y < top + k; y++) {
      fillU32(cells, y * w + x0, y * w + x1, kBlank);
      fillU32(styles, y * w + x0, y * w + x1, style.value);
      _moveDamage(y, -1, x0, x1);
    }
  }
  pendingScrolls
    ..add(top)
    ..add(bottom)
    ..add(n)
    ..add(x0)
    ..add(x1);
}