diff --git a/src/ui/bigtext/highlight_regex.py b/src/ui/bigtext/highlight_regex.py index b2322e6..40a91e8 100644 --- a/src/ui/bigtext/highlight_regex.py +++ b/src/ui/bigtext/highlight_regex.py @@ -64,19 +64,21 @@ class HighlightRegex(Highlight): match_iter = re.finditer(self.regex, line.line()) for match in match_iter: # print("%s" % match) - start_char = match.start(0) - end_char = match.end(0) - start_column = line.char_to_column(start_char) - end_column = line.char_to_column(end_char) - - result.append(HighlightedRange( - start_column, - end_column - start_column, - highlight_full_line=True, - brush=self._brush_hit, - brush_full_line=self._brush_line - )) + # if the regex has groups then skip the first, it represents the whole match, + # but we only want to highlight the groups + first_group = 1 if len(match.groups()) > 0 else 0 + for i in range(first_group, len(match.groups()) + 1): + start_column = line.char_to_column(match.start(i)) + end_column = line.char_to_column(match.end(i)) + # print(f"highlight: {start_column}:{end_column} - {match.group(i)}") + result.append(HighlightedRange( + start_column, + end_column - start_column, + highlight_full_line=True, + brush=self._brush_hit, + brush_full_line=self._brush_line + )) return result