Fixed out of bounds error in List. Fixes #480

This commit is contained in:
Oliver 2022-11-27 22:21:15 +01:00
parent 09f052e6ca
commit f5cddba6f0
1 changed files with 2 additions and 2 deletions

View File

@ -150,7 +150,7 @@ func (l *List) GetOffset() (int, int) {
// always removed. // always removed.
// //
// The currently selected item is shifted accordingly. If it is the one that is // 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 { func (l *List) RemoveItem(index int) *List {
if len(l.items) == 0 { if len(l.items) == 0 {
return l return l
@ -177,7 +177,7 @@ func (l *List) RemoveItem(index int) *List {
// Shift current item. // Shift current item.
previousCurrentItem := l.currentItem previousCurrentItem := l.currentItem
if l.currentItem >= index { if l.currentItem > index || l.currentItem == len(l.items) {
l.currentItem-- l.currentItem--
} }