From f5cddba6f0d3b7d0704b17b37d4aec56bc6c6fca Mon Sep 17 00:00:00 2001 From: Oliver <480930+rivo@users.noreply.github.com> Date: Sun, 27 Nov 2022 22:21:15 +0100 Subject: [PATCH] Fixed out of bounds error in List. Fixes #480 --- list.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/list.go b/list.go index 3be92e7..a01936d 100644 --- a/list.go +++ b/list.go @@ -150,7 +150,7 @@ func (l *List) GetOffset() (int, int) { // always removed. // // The currently selected item is shifted accordingly. If it is the one that is -// removed, a "changed" event is fired. +// removed, a "changed" event is fired, unless no items are left. func (l *List) RemoveItem(index int) *List { if len(l.items) == 0 { return l @@ -177,7 +177,7 @@ func (l *List) RemoveItem(index int) *List { // Shift current item. previousCurrentItem := l.currentItem - if l.currentItem >= index { + if l.currentItem > index || l.currentItem == len(l.items) { l.currentItem-- }