asList method

List<String> asList({
  1. required Position start,
  2. required Position end,
  3. bool isInclusive = false,
  4. List<String>? list,
})

Returns the text between two positions as a string list. start ist the position to start. end is the the end of the wanted text. if isInclusive is true end is part of the returned text.

Implementation

List<String> asList(
    {required Position start,
    required Position end,
    bool isInclusive = false,
    List<String>? list}) {
  list ??= [];
  list.clear();
  if (start.isAbove(end, orEqual: isInclusive)) {
    if (start.line == end.line) {
      list.add(lines[start.line]
          .substring(start.column, end.column + (isInclusive ? 1 : 0)));
    } else {
      // first line may be a part:
      list.add(start.column == 0
          ? lines[start.line]
          : lines[start.line].substring(start.column));
      for (var ix = start.line + 1; ix < end.line; ix++) {
        list.add(lines[ix]);
      }
      // last line may be a part:
      if (end.column == 0) {
        if (isInclusive) {
          list.add('');
        }
      } else {
        list.add(
            lines[end.line].substring(0, end.column + (isInclusive ? 1 : 0)));
      }
    }
  }
  return list;
}