Remove scroll looping

This commit is contained in:
FIGBERT 2023-04-20 10:12:08 -07:00
parent 81018c2da7
commit 03f8db40a0
No known key found for this signature in database
GPG key ID: 67F1598D607A844B

View file

@ -141,10 +141,10 @@ func (rstr *RosterView) Last() *rooms.Room {
} }
func (rstr *RosterView) ScrollNext() { func (rstr *RosterView) ScrollNext() {
if index := rstr.index(rstr.selected); index == -1 || index == len(rstr.rooms)-1 { if index := rstr.index(rstr.selected); index == -1 {
rstr.selected = rstr.First() rstr.selected = rstr.First()
rstr.scrollOffset = 0 rstr.scrollOffset = 0
} else { } else if index < len(rstr.rooms)-1 {
rstr.Lock() rstr.Lock()
defer rstr.Unlock() defer rstr.Unlock()
rstr.selected = rstr.rooms[index+1] rstr.selected = rstr.rooms[index+1]
@ -155,15 +155,7 @@ func (rstr *RosterView) ScrollNext() {
} }
func (rstr *RosterView) ScrollPrev() { func (rstr *RosterView) ScrollPrev() {
if index := rstr.index(rstr.selected); index < 1 { if index := rstr.index(rstr.selected); index > 0 {
rstr.selected = rstr.Last()
if i := len(rstr.rooms) - rstr.RoomsOnScreen(); i < 0 {
rstr.scrollOffset = 0
} else {
rstr.scrollOffset = i
}
} else {
rstr.Lock() rstr.Lock()
defer rstr.Unlock() defer rstr.Unlock()
rstr.selected = rstr.rooms[index-1] rstr.selected = rstr.rooms[index-1]