fix: search entry with no group
This commit is contained in:
parent
039b430e7d
commit
0bf248d70e
2 changed files with 14 additions and 6 deletions
14
gpm/cli.go
14
gpm/cli.go
|
@ -140,7 +140,7 @@ func (c *Cli) GroupsBox() string {
|
|||
l.SelectedRowStyle = ui.NewStyle(ui.ColorGreen, ui.ColorClear, ui.ModifierBold)
|
||||
l.WrapText = false
|
||||
l.SetRect(0, 0, 25, 23)
|
||||
l.Rows = c.Wallet.Groups()
|
||||
l.Rows = append(c.Wallet.Groups(), "No group")
|
||||
|
||||
uiEvents := ui.PollEvents()
|
||||
for {
|
||||
|
@ -309,6 +309,7 @@ func (c *Cli) ListEntries(ch chan<- bool) {
|
|||
var selected bool
|
||||
|
||||
refresh := true
|
||||
noGroup := false
|
||||
index := -1
|
||||
|
||||
l := widgets.NewList()
|
||||
|
@ -322,6 +323,8 @@ func (c *Cli) ListEntries(ch chan<- bool) {
|
|||
for {
|
||||
if group != "" {
|
||||
l.Title = fmt.Sprintf("Group: %s", group)
|
||||
} else if noGroup {
|
||||
l.Title = "Group: No group"
|
||||
} else {
|
||||
l.Title = "Group: All"
|
||||
}
|
||||
|
@ -329,7 +332,7 @@ func (c *Cli) ListEntries(ch chan<- bool) {
|
|||
if refresh {
|
||||
refresh = false
|
||||
index = -1
|
||||
entries = c.Wallet.SearchEntry(pattern, group)
|
||||
entries = c.Wallet.SearchEntry(pattern, group, noGroup)
|
||||
l.Rows = []string{}
|
||||
for _, entry := range entries {
|
||||
l.Rows = append(l.Rows, entry.Name)
|
||||
|
@ -361,7 +364,7 @@ func (c *Cli) ListEntries(ch chan<- bool) {
|
|||
index = l.SelectedRow
|
||||
case "<Escape>":
|
||||
pattern = ""
|
||||
group = ""
|
||||
group = "all"
|
||||
refresh = true
|
||||
case "n":
|
||||
refresh = c.AddEntry()
|
||||
|
@ -378,6 +381,11 @@ func (c *Cli) ListEntries(ch chan<- bool) {
|
|||
refresh = true
|
||||
case "g":
|
||||
group = c.GroupsBox()
|
||||
noGroup = false
|
||||
if group == "No group" {
|
||||
group = ""
|
||||
noGroup = true
|
||||
}
|
||||
refresh = true
|
||||
case "j", "<Down>":
|
||||
if len(entries) > 0 {
|
||||
|
|
|
@ -126,12 +126,12 @@ func (w *Wallet) Groups() []string {
|
|||
}
|
||||
|
||||
// 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
|
||||
r := regexp.MustCompile(strings.ToLower(pattern))
|
||||
|
||||
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
|
||||
}
|
||||
if r.Match([]byte(strings.ToLower(entry.Name))) ||
|
||||
|
|
Loading…
Reference in a new issue