hints kitten: Fix a regression in 0.28.0 that broke using sub-groups in regexp captures

Fixes #6228
This commit is contained in:
Kovid Goyal 2023-04-30 21:16:24 +05:30
parent f6ccd2ad2c
commit 1fc4e53bea
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 14 additions and 1 deletions

View File

@ -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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -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,
})

View File

@ -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")