diff options
author | Luke Adams <lukeclydeadams@gmail.com> | 2018-10-16 14:13:04 -0600 |
---|---|---|
committer | Luke Adams <lukeclydeadams@gmail.com> | 2018-10-16 14:13:04 -0600 |
commit | 3eedb6f65a5951d43ed463c8959443ad7e59cc1a (patch) | |
tree | e69fc527a2067c0896eefe640ad0f4b593f99c02 /termui/label_select.go | |
parent | 788cdb0633d71f881c709941311c768280fbb33e (diff) | |
download | git-bug-3eedb6f65a5951d43ed463c8959443ad7e59cc1a.tar.gz |
Fix error when label list is empty
Diffstat (limited to 'termui/label_select.go')
-rw-r--r-- | termui/label_select.go | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/termui/label_select.go b/termui/label_select.go index 1a19a9e5..5a0793f7 100644 --- a/termui/label_select.go +++ b/termui/label_select.go @@ -42,7 +42,12 @@ func (ls *labelSelect) SetBug(cache *cache.RepoCache, bug *cache.BugCache) { } ls.labelSelect = labelSelect - ls.selected = 0 + if len(labelSelect) > 0 { + ls.selected = 0 + } else { + ls.selected = -1 + } + ls.scroll = 0 } @@ -166,6 +171,10 @@ func (ls *labelSelect) disable(g *gocui.Gui) error { } func (ls *labelSelect) focusView(g *gocui.Gui) error { + if ls.selected < 0 { + return nil + } + _, lsy0, _, lsy1, err := g.ViewPosition(labelSelectView) if err != nil { return err @@ -191,16 +200,28 @@ func (ls *labelSelect) focusView(g *gocui.Gui) error { } func (ls *labelSelect) selectPrevious(g *gocui.Gui, v *gocui.View) error { + if ls.selected < 0 { + return nil + } + ls.selected = maxInt(0, ls.selected-1) return ls.focusView(g) } func (ls *labelSelect) selectNext(g *gocui.Gui, v *gocui.View) error { + if ls.selected < 0 { + return nil + } + ls.selected = minInt(len(ls.labels)-1, ls.selected+1) return ls.focusView(g) } func(ls *labelSelect) selectItem(g *gocui.Gui, v *gocui.View) error { + if ls.selected < 0 { + return nil + } + ls.labelSelect[ls.selected] = !ls.labelSelect[ls.selected] return nil } |