moveWordForward function

int moveWordForward(
  1. List<String> graphemes,
  2. int offset, {
  3. required GraphemePredicate isWord,
})

Implementation

int moveWordForward(
  List<String> graphemes,
  int offset, {
  required GraphemePredicate isWord,
}) {
  if (offset >= graphemes.length || graphemes.isEmpty) {
    return graphemes.length;
  }

  var position = offset + 1;
  while (position < graphemes.length && !isWord(graphemes[position])) {
    position++;
  }
  while (position < graphemes.length && isWord(graphemes[position])) {
    position++;
  }
  return position.clamp(0, graphemes.length);
}