mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-16 01:43:21 +00:00
Merge pull request #783 from s0ders/fix/table-cursor-out-of-bounds
fix(table): preventing cursor from being out-of-bounds.
This commit is contained in:
+9
-3
@@ -4,12 +4,13 @@ package table
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/help"
|
|
||||||
"github.com/charmbracelet/bubbles/key"
|
|
||||||
"github.com/charmbracelet/bubbles/viewport"
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/mattn/go-runewidth"
|
"github.com/mattn/go-runewidth"
|
||||||
|
|
||||||
|
"github.com/charmbracelet/bubbles/help"
|
||||||
|
"github.com/charmbracelet/bubbles/key"
|
||||||
|
"github.com/charmbracelet/bubbles/viewport"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Model defines a state for the table widget.
|
// Model defines a state for the table widget.
|
||||||
@@ -306,6 +307,11 @@ func (m Model) Columns() []Column {
|
|||||||
// SetRows sets a new rows state.
|
// SetRows sets a new rows state.
|
||||||
func (m *Model) SetRows(r []Row) {
|
func (m *Model) SetRows(r []Row) {
|
||||||
m.rows = r
|
m.rows = r
|
||||||
|
|
||||||
|
if m.cursor > len(m.rows)-1 {
|
||||||
|
m.cursor = len(m.rows) - 1
|
||||||
|
}
|
||||||
|
|
||||||
m.UpdateViewport()
|
m.UpdateViewport()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user