getWordBoundary method

BufferRangeLine? getWordBoundary(
  1. CellOffset position
)

Implementation

BufferRangeLine? getWordBoundary(CellOffset position) {
  var separators = wordSeparators ?? defaultWordSeparators;
  if (position.y >= lines.length) {
    return null;
  }

  var line = lines[position.y];
  var start = position.x;
  var end = position.x;

  do {
    if (start == 0) {
      break;
    }
    final char = line.getCodePoint(start - 1);
    if (separators.contains(char)) {
      break;
    }
    start--;
  } while (true);

  do {
    if (end >= viewWidth) {
      break;
    }
    final char = line.getCodePoint(end);
    if (separators.contains(char)) {
      break;
    }
    end++;
  } while (true);

  if (start == end) {
    return null;
  }

  return BufferRangeLine(
    CellOffset(start, position.y),
    CellOffset(end, position.y),
  );
}