From 263c9776dfda18bf9bb22d24dc26cbf61c6072fa Mon Sep 17 00:00:00 2001 From: M0hammadUsman Date: Wed, 9 Apr 2025 08:46:42 +0500 Subject: [PATCH] fix: Selected row styling not applying to cells. - Now applies necessary selected row styling to the individual cells. --- table/table.go | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/table/table.go b/table/table.go index ed29d8c53..e04fdbcbe 100644 --- a/table/table.go +++ b/table/table.go @@ -426,19 +426,46 @@ func (m *Model) renderRow(r int) string { continue } style := lipgloss.NewStyle().Width(m.cols[i].Width).MaxWidth(m.cols[i].Width).Inline(true) - renderedCell := m.styles.Cell.Render(style.Render(runewidth.Truncate(value, m.cols[i].Width, "…"))) + cellContent := style.Render(runewidth.Truncate(value, m.cols[i].Width, "…")) + cellStyle := m.styles.Cell + if r == m.cursor { + // borrows necessary selected row styling + cellStyle = m.getSelRowCellStyle() + } + renderedCell := cellStyle.Render(cellContent) s = append(s, renderedCell) } row := lipgloss.JoinHorizontal(lipgloss.Top, s...) if r == m.cursor { - return m.styles.Selected.Render(row) + // if not unset, these styles will break cell styling + return m.styles.Selected. + UnsetUnderline(). + UnsetUnderlineSpaces(). + UnsetStrikethrough(). + UnsetStrikethroughSpaces(). + Render(row) } return row } +func (m Model) getSelRowCellStyle() lipgloss.Style { + s := m.styles.Selected + return m.styles.Cell.Foreground(s.GetForeground()). + Background(s.GetBackground()). + Italic(s.GetItalic()). + Bold(s.GetBold()). + Blink(s.GetBlink()). + Reverse(s.GetReverse()). + Faint(s.GetFaint()). + Underline(s.GetUnderline()). + UnderlineSpaces(s.GetUnderlineSpaces()). + Strikethrough(s.GetStrikethrough()). + StrikethroughSpaces(s.GetStrikethroughSpaces()) +} + func clamp(v, low, high int) int { return min(max(v, low), high) }