find method

int find(
  1. int col,
  2. int delta
)

Finds a tab stop relative to col moving by delta.

Implementation

int find(int col, int delta) {
  if (delta == 0) return col;

  var prev = false;
  var count = delta;
  if (count < 0) {
    count = -count;
    prev = true;
  }

  while (count > 0) {
    if (!prev) {
      if (col >= width - 1) return col;
      col++;
    } else {
      if (col < 1) return col;
      col--;
    }

    if (isStop(col)) count--;
  }

  return col;
}