diff options
author | Elwardi <elwardifadeli@gmail.com> | 2021-07-19 13:06:00 +0100 |
---|---|---|
committer | Elwardi <elwardifadeli@gmail.com> | 2021-07-19 13:06:00 +0100 |
commit | b92ff3ee3fdde05ac84f2790e6b10a10db0c4d2a (patch) | |
tree | af7a1384e2e7ded130029033052c64f1bcf357b8 /pkg | |
parent | f1ced5539a9a53ea5c8e501243377d3c74cef2d5 (diff) |
Consider first match only in menuFromCommand prompt
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/custom_commands.go | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/pkg/gui/custom_commands.go b/pkg/gui/custom_commands.go index fbe92a72f..1ac92f49c 100644 --- a/pkg/gui/custom_commands.go +++ b/pkg/gui/custom_commands.go @@ -184,31 +184,28 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand // Need to make a menu out of what the cmd has displayed candidates := []string{} + buff := bytes.NewBuffer(nil) temp := template.Must(template.New("format").Parse(prompt.Format)) for _, str := range strings.Split(string(message), "\n") { if str == "" { continue } - buff := bytes.NewBuffer(nil) - groupNames := reg.SubexpNames() tmplData := map[string]string{} - for matchNum, match := range reg.FindAllStringSubmatch(str, -1) { - if len(match) > 0 { - for groupIdx, group := range match { - // Record matched group with group and match ids - matchName := "group_" + strconv.Itoa(groupIdx) + "_" + strconv.Itoa(matchNum) - tmplData[matchName] = group - // Record last named group non-empty matches as group matches - name := groupNames[groupIdx] - _, ok := tmplData[name] - if name != "" && group != "" && !ok { - tmplData[name] = group - } + out := reg.FindAllStringSubmatch(str, -1) + if len(out) > 0 { + for groupIdx, group := range reg.SubexpNames() { + // Record matched group with group ids + matchName := "group_" + strconv.Itoa(groupIdx) + tmplData[matchName] = group + // Record last named group non-empty matches as group matches + if group != "" { + tmplData[group] = out[0][idx] } } } temp.Execute(buff, tmplData) candidates = append(candidates, strings.TrimSpace(buff.String())) + buff.Reset() } menuItems := make([]*menuItem, len(candidates)) |