diff --git a/docs/changelog.rst b/docs/changelog.rst index 93e9bf58c..a99116fa3 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -48,6 +48,8 @@ Detailed list of changes - show_key kitten: In kitty mode show the actual bytes sent by the terminal rather than a re-encoding of the parsed key event +- hints kitten: Fix a regression in 0.28.0 that broke using sub-groups in regexp captures (:iss:`6228`) + 0.28.1 [2023-04-21] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kittens/hints/marks.go b/kittens/hints/marks.go index 78b754b0a..f61cc9276 100644 --- a/kittens/hints/marks.go +++ b/kittens/hints/marks.go @@ -314,6 +314,12 @@ func mark(r *regexp.Regexp, post_processors []PostProcessorFunc, group_processor for k, v := range gd { gd2[k] = v } + if opts.Type == "regex" && len(names) > 1 && names[1] == "" { + ms, me := v[2], v[3] + match_start = utils.Max(match_start, ms) + match_end = utils.Min(match_end, me) + full_match = sanitize_pat.ReplaceAllLiteralString(text[match_start:match_end], "") + } ans = append(ans, Mark{ Index: i, Start: match_start, End: match_end, Text: full_match, Groupdict: gd2, }) diff --git a/kittens/hints/marks_test.go b/kittens/hints/marks_test.go index 3f5a851b5..f92234971 100644 --- a/kittens/hints/marks_test.go +++ b/kittens/hints/marks_test.go @@ -47,7 +47,7 @@ func TestHintMarking(t *testing.T) { for _, m := range marks { q := strings.NewReplacer("\n", "", "\r", "", "\x00", "").Replace(ptext[m.Start:m.End]) if diff := cmp.Diff(m.Text, q); diff != "" { - t.Fatalf("Mark start and end dont point to correct offset in text for %#v\n%s", text, diff) + t.Fatalf("Mark start (%d) and end (%d) dont point to correct offset in text for %#v\n%s", m.Start, m.End, text, diff) } } return @@ -107,6 +107,11 @@ func TestHintMarking(t *testing.T) { r(`255.255.255.256`) r(`:1`) + reset() + opts.Type = "regex" + opts.Regex = `(?ms)^[*]?\s(\S+)` + r(`* 2b687c2 - test1`, `2b687c2`) + reset() tdir := t.TempDir() simple := filepath.Join(tdir, "simple.py")