Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
contact list should now scroll properly (#38)
Browse files Browse the repository at this point in the history
Co-authored-by: Derric Williams <wilzder@amazon.com>
  • Loading branch information
derricw and Derric Williams committed Feb 14, 2021
1 parent 93fed9c commit 1c9840a
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions widgets/contactlist.go
Expand Up @@ -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]
}

Expand Down

0 comments on commit 1c9840a

Please sign in to comment.