From 9d1ca6feec14a4f30281cdf15ec29b6d464c44dd 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 6519dfb5c..3bdf5c022 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] }