findRegex method

void findRegex(
  1. RegExp regex,
  2. TextStyle? highlightStyle
)

Implementation

void findRegex(RegExp regex, TextStyle? highlightStyle) {
  final style =
      highlightStyle ?? const TextStyle(backgroundColor: Colors.amberAccent);

  searchHighlights.clear();

  final searchText = text;
  final matches = regex.allMatches(searchText);

  for (final match in matches) {
    searchHighlights.add(
      SearchHighlight(start: match.start, end: match.end, style: style),
    );
  }

  searchHighlightsChanged = true;
  notifyListeners();
}