From 7ba044773bfea886af88894af97023fad285c2a3 Mon Sep 17 00:00:00 2001 From: Mikael Fangel <34864484+MikaelFangel@users.noreply.github.com> Date: Sat, 11 Mar 2023 15:47:31 +0100 Subject: [PATCH] fix: add bounds checking to the selectedrow func (#351) --- table/table.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/table/table.go b/table/table.go index 6519dfb..3bdf5c0 100644 --- a/table/table.go +++ b/table/table.go @@ -266,6 +266,10 @@ func (m *Model) UpdateViewport() { // SelectedRow returns the selected row. // You can cast it to your own implementation. func (m Model) SelectedRow() Row { + if m.cursor < 0 || m.cursor >= len(m.rows) { + return nil + } + return m.rows[m.cursor] }