unchangedRanges static method

Future<List<Range>> unchangedRanges({
  1. required String input,
  2. required List<String> results,
})

Returns the range of the text which has not been changed by the completions for each completion.

Can be used to bold the unchanged part, the part typed by the user.

Example

input: "Linus T" -> completion: "Linus Torvalds". The unchanged range is from 'L' to 'T' so 0 to 6.

Implementation

static Future<List<Range>> unchangedRanges({
  required String input,
  required List<String> results,
}) async {
  var ranges = <Range>[];

  for (final result in results) {
    final ix = result.toLowerCase().indexOf(input.toLowerCase());
    ranges.add(Range(start: ix, end: ix + input.length));
  }

  return ranges;
}