Skip to content

Commit

Permalink
fix: add bounds checking to the selectedrow func (charmbracelet#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelFangel authored Mar 11, 2023
1 parent bac0f18 commit 9d1ca6f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down

0 comments on commit 9d1ca6f

Please sign in to comment.