-
Notifications
You must be signed in to change notification settings - Fork 230
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
fix: shared indices for first row of data and headers (StyleFunc bug) #377
Conversation
This is the test that reproduces the behaviour I was seeing in the bubble (in the screenshots above) https://github.com/charmbracelet/lipgloss/blob/fix-stylefunc/table/table_test.go#L1144-L1169 |
@@ -7,6 +7,10 @@ import ( | |||
"github.com/charmbracelet/x/ansi" | |||
) | |||
|
|||
// HeaderRow denotes the header's row index used when rendering headers. Use | |||
// this value when looking to customize header styles in StyleFunc. | |||
const HeaderRow int = -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be exported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is the value they would be using in StyleFunc
to style the header instead of 0. I figured better to export a const than have them check for -1
Ah, wait, this is Lip Gloss. Okay, will poke around on this one. |
@meowgorithm the tests are probably the best place to see the changes! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done 👌
lipgloss changed the row numbering in this PR (charmbracelet/lipgloss#377)
lipgloss changed the row numbering in this PR (charmbracelet/lipgloss#377)
While migrating the table bubble to use Lip Gloss, I noticed some rendering issues where the cursor was constantly off by one. After fixing the off by one error, I was still having some range issues where the first element was never showing the selected style. Turns out, both the first element in the list and the header are the same index, so whatever style was returned first would be rendered by both the header and first element in the list.
Despite the cursor being in the right position, it was rendering the next element in the list with the declared styles.
Note
This is a bit of a breaking change, though necessary for the first element to ever render correctly when there are also styles set on the headers. This would require table users to update their
StyleFunc
implementations to useHeaderRow
instead of 0.Before:
After:
(it's failing intentionally so I could see the outputs)
This PR introduces a test to Lip Gloss that adds unique styles to both the header and first row of data to showcase the issue. When running the test against
master
, you'd need to comment out theHeaderRow
stuff and you'll see that both the first row and header use the same style.