From 1c9840a036274bb0e3c0c39483c8c3219f90b8be Mon Sep 17 00:00:00 2001 From: Derric Williams Date: Sun, 14 Feb 2021 00:22:14 -0800 Subject: [PATCH] contact list should now scroll properly (#38) Co-authored-by: Derric Williams --- widgets/contactlist.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/widgets/contactlist.go b/widgets/contactlist.go index 3d46488..bf4fd00 100644 --- a/widgets/contactlist.go +++ b/widgets/contactlist.go @@ -19,33 +19,24 @@ type ContactListPanel struct { } func (cl *ContactListPanel) Next() *model.Contact { - if cl.currentIndex < len(cl.sortedContacts)-1 { - cl.currentIndex++ - } else { - cl.currentIndex = 0 // loop around - } - return cl.sortedContacts[cl.currentIndex] + return cl.GotoIndex(cl.currentIndex + 1) } func (cl *ContactListPanel) Previous() *model.Contact { - if cl.currentIndex > 0 { - cl.currentIndex-- - } else { - cl.currentIndex = len(cl.sortedContacts) - 1 // loop around - } - return cl.sortedContacts[cl.currentIndex] + return cl.GotoIndex(cl.currentIndex - 1) } // GotoIndex goes to a particular contact index and return the Contact. Negative indexing is // allowed. func (cl *ContactListPanel) GotoIndex(index int) *model.Contact { if index < 0 { - return cl.GotoIndex(len(cl.sortedContacts) - index) + return cl.GotoIndex(len(cl.sortedContacts) + index) } if index >= len(cl.sortedContacts) { - return cl.GotoIndex(-1) + index = 0 } cl.currentIndex = index + cl.ScrollTo(cl.currentIndex, 0) return cl.sortedContacts[index] }