touchLine method

void touchLine(
  1. int x,
  2. int y,
  3. int width
)

Implementation

void touchLine(int x, int y, int width) {
  if (y < 0 || y >= lines.length) return;

  if (y >= touched.length) {
    touched = [
      ...touched,
      ...List<LineData?>.filled(y - touched.length + 1, null),
    ];
  }

  final ch = touched[y];
  final first = x;
  final last = x + width;
  if (ch == null) {
    touched[y] = LineData(firstCell: first, lastCell: last);
  } else {
    final prevFirst = ch.firstCell == -1 ? first : ch.firstCell;
    final prevLast = ch.lastCell == -1 ? last : ch.lastCell;
    touched[y] = LineData(
      firstCell: first < prevFirst ? first : prevFirst,
      lastCell: last > prevLast ? last : prevLast,
    );
  }
}