diff --git a/wdgt_simple_list.go b/wdgt_simple_list.go index eaa5fc1..22ea14f 100644 --- a/wdgt_simple_list.go +++ b/wdgt_simple_list.go @@ -227,6 +227,12 @@ func (w *SimpleList) MinW() int { func (w *SimpleList) MinH() int { return 4 } +func (w *SimpleList) getItemAt(idx int) { + for idx >= len(w.List) { + idx-- + } + +} func (w *SimpleList) SetCursorWrap(b bool) { w.cursorWrap = b } func (w *SimpleList) MoveUp() bool { if w.cursor > 0 { @@ -328,7 +334,12 @@ func (w *SimpleList) SetItem(idx int, txt string) { w.list[idx] = txt } } -func (w *SimpleList) SelectedIndex() int { return w.cursor } +func (w *SimpleList) SelectedIndex() int { + if w.cursor >= len(w.list) { + w.cursor = len(w.list) - 1 + } + return w.cursor +} func (w *SimpleList) SetSelectedIndex(i int) { if i < 0 { i = 0 @@ -350,6 +361,11 @@ func (w *SimpleList) Log(txt string, args ...any) { func (w *SimpleList) SetOnChange(c func(int, string) bool) { w.onChange = c } -func (w *SimpleList) GetSelectedItem() string { return w.list[w.cursor] } +func (w *SimpleList) GetSelectedItem() string { + if w.cursor >= len(w.list) { + w.cursor = len(w.list) - 1 + } + return w.list[w.cursor] +} func (w *SimpleList) GetAllItems() []string { return w.list } func (w *SimpleList) GetAllItemStyles() map[int]tcell.Style { return w.itemsStyle }