Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlighted row in table jumping out of view #733

Open
aodhan-domhnaill opened this issue Feb 11, 2025 · 0 comments
Open

Highlighted row in table jumping out of view #733

aodhan-domhnaill opened this issue Feb 11, 2025 · 0 comments

Comments

@aodhan-domhnaill
Copy link

aodhan-domhnaill commented Feb 11, 2025

When I try something like this here https://github.com/charmbracelet/bubbletea/blob/cb6f8402f63d74df566577015ef10a75335eb242/examples/table/main.go#L25

		case "tab":
			m.table.SetCursor(m.table.Cursor() + 9)

The highlighted row can jump out of view.

Looking at this, I see a couple things

bubbles/table/table.go

Lines 344 to 362 in 0f9e38c

// SetCursor sets the cursor position in the table.
func (m *Model) SetCursor(n int) {
m.cursor = clamp(n, 0, len(m.rows)-1)
m.UpdateViewport()
}
// MoveUp moves the selection up by any number of rows.
// It can not go above the first row.
func (m *Model) MoveUp(n int) {
m.cursor = clamp(m.cursor-n, 0, len(m.rows)-1)
switch {
case m.start == 0:
m.viewport.SetYOffset(clamp(m.viewport.YOffset, 0, m.cursor))
case m.start < m.viewport.Height:
m.viewport.YOffset = (clamp(clamp(m.viewport.YOffset+n, 0, m.cursor), 0, m.viewport.Height))
case m.viewport.YOffset >= 1:
m.viewport.YOffset = clamp(m.viewport.YOffset+n, 1, m.viewport.Height)
}
m.UpdateViewport()

  1. Lines 358 and 360 don't follow the pattern of calling SetYOffset. Probably not a problem, but thought I'd point it out incase it was a mistake
  2. SetCursor doesn't do this ViewPort clamping. Is this the issue? We can't access viewport from a user API, so it would need to be fixed in the main code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant