textSearchDecorations function

List<TextDecorationRange> textSearchDecorations(
  1. Iterable<TextHighlightRange> matches, {
  2. int activeIndex = -1,
})

Implementation

List<TextDecorationRange> textSearchDecorations(
  Iterable<TextHighlightRange> matches, {
  int activeIndex = -1,
}) {
  final normalizedMatches = matches.toList(growable: false);
  if (normalizedMatches.isEmpty) {
    return const [];
  }

  final normalizedActiveIndex =
      activeIndex < 0 || activeIndex >= normalizedMatches.length
      ? -1
      : activeIndex;

  return List<TextDecorationRange>.unmodifiable([
    for (var index = 0; index < normalizedMatches.length; index++)
      TextDecorationRange(
        startOffset: normalizedMatches[index].startOffset,
        endOffset: normalizedMatches[index].endOffset,
        styleKey: index == normalizedActiveIndex
            ? textSearchActiveMatchDecorationKey
            : textSearchMatchDecorationKey,
      ),
  ]);
}