fix: search entry with no group

This commit is contained in:
Adrien Waksberg 2020-12-22 17:23:13 +01:00
parent 039b430e7d
commit 0bf248d70e
2 changed files with 14 additions and 6 deletions

View file

@ -140,7 +140,7 @@ func (c *Cli) GroupsBox() string {
l.SelectedRowStyle = ui.NewStyle(ui.ColorGreen, ui.ColorClear, ui.ModifierBold) l.SelectedRowStyle = ui.NewStyle(ui.ColorGreen, ui.ColorClear, ui.ModifierBold)
l.WrapText = false l.WrapText = false
l.SetRect(0, 0, 25, 23) l.SetRect(0, 0, 25, 23)
l.Rows = c.Wallet.Groups() l.Rows = append(c.Wallet.Groups(), "No group")
uiEvents := ui.PollEvents() uiEvents := ui.PollEvents()
for { for {
@ -309,6 +309,7 @@ func (c *Cli) ListEntries(ch chan<- bool) {
var selected bool var selected bool
refresh := true refresh := true
noGroup := false
index := -1 index := -1
l := widgets.NewList() l := widgets.NewList()
@ -322,6 +323,8 @@ func (c *Cli) ListEntries(ch chan<- bool) {
for { for {
if group != "" { if group != "" {
l.Title = fmt.Sprintf("Group: %s", group) l.Title = fmt.Sprintf("Group: %s", group)
} else if noGroup {
l.Title = "Group: No group"
} else { } else {
l.Title = "Group: All" l.Title = "Group: All"
} }
@ -329,7 +332,7 @@ func (c *Cli) ListEntries(ch chan<- bool) {
if refresh { if refresh {
refresh = false refresh = false
index = -1 index = -1
entries = c.Wallet.SearchEntry(pattern, group) entries = c.Wallet.SearchEntry(pattern, group, noGroup)
l.Rows = []string{} l.Rows = []string{}
for _, entry := range entries { for _, entry := range entries {
l.Rows = append(l.Rows, entry.Name) l.Rows = append(l.Rows, entry.Name)
@ -361,7 +364,7 @@ func (c *Cli) ListEntries(ch chan<- bool) {
index = l.SelectedRow index = l.SelectedRow
case "<Escape>": case "<Escape>":
pattern = "" pattern = ""
group = "" group = "all"
refresh = true refresh = true
case "n": case "n":
refresh = c.AddEntry() refresh = c.AddEntry()
@ -378,6 +381,11 @@ func (c *Cli) ListEntries(ch chan<- bool) {
refresh = true refresh = true
case "g": case "g":
group = c.GroupsBox() group = c.GroupsBox()
noGroup = false
if group == "No group" {
group = ""
noGroup = true
}
refresh = true refresh = true
case "j", "<Down>": case "j", "<Down>":
if len(entries) > 0 { if len(entries) > 0 {

View file

@ -126,12 +126,12 @@ func (w *Wallet) Groups() []string {
} }
// SearchEntry return an array with the array expected with the pattern // SearchEntry return an array with the array expected with the pattern
func (w *Wallet) SearchEntry(pattern string, group string) []Entry { func (w *Wallet) SearchEntry(pattern string, group string, noGroup bool) []Entry {
var entries []Entry var entries []Entry
r := regexp.MustCompile(strings.ToLower(pattern)) r := regexp.MustCompile(strings.ToLower(pattern))
for _, entry := range w.Entries { for _, entry := range w.Entries {
if group != "" && strings.ToLower(entry.Group) != strings.ToLower(group) { if (noGroup && entry.Group != "") || (!noGroup && group != "" && strings.ToLower(entry.Group) != strings.ToLower(group)) {
continue continue
} }
if r.Match([]byte(strings.ToLower(entry.Name))) || if r.Match([]byte(strings.ToLower(entry.Name))) ||