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) {
searchHighlights.clear();
final searchText = text;
final matches = regex.allMatches(searchText);
for (final match in matches) {
searchHighlights.add(
SearchHighlight(
start: match.start,
end: match.end,
isCurrentMatch: true,
),
);
}
searchHighlightsChanged = true;
notifyListeners();
}