findRegex method
Search the document using a regular expression and add highlight ranges for each match.
regex: The regular expression used to find matches in the current document text. All matches returned byregex.allMatchesare added as highlights.highlightStyle: OptionalTextStyleapplied to each match. If null, a default amber background style is used.
Behavior:
Clears existing searchHighlights, applies regex to the document
text, appends a SearchHighlight for every match and then sets
searchHighlightsChanged = true and calls notifyListeners().
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();
}