mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-25 17:53:24 +01:00
Add support for horizontal scrolling of all columns for #188
This commit is contained in:
parent
4dc97291c3
commit
1d26ca109b
@ -1792,6 +1792,8 @@ func testTui_scroll(t *testing.T) {
|
|||||||
out = stripTuiCommandPrefix(t, out)
|
out = stripTuiCommandPrefix(t, out)
|
||||||
testutils.CompareGoldens(t, out, "TestTui-RightScrollTwo")
|
testutils.CompareGoldens(t, out, "TestTui-RightScrollTwo")
|
||||||
|
|
||||||
|
// TODO: Add a test here that shows all columns can be horizontally scrolled
|
||||||
|
|
||||||
// Assert there are no leaked connections
|
// Assert there are no leaked connections
|
||||||
assertNoLeakedConnections(t)
|
assertNoLeakedConnections(t)
|
||||||
}
|
}
|
||||||
|
@ -358,11 +358,11 @@ func (m *Model) MaxHScroll() int {
|
|||||||
maxWidth := 0
|
maxWidth := 0
|
||||||
index := m.ColIndex(m.hcol)
|
index := m.ColIndex(m.hcol)
|
||||||
for _, row := range m.rows {
|
for _, row := range m.rows {
|
||||||
if len(row) > index {
|
for _, value := range row {
|
||||||
maxWidth = max(len(row[index]), maxWidth)
|
maxWidth = max(runewidth.StringWidth(value), maxWidth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return max(maxWidth-m.cols[index].Width+1, 0)
|
return max(maxWidth-m.cols[index].Width+2, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetWidth sets the width of the viewport of the table.
|
// SetWidth sets the width of the viewport of the table.
|
||||||
@ -478,6 +478,17 @@ func (m Model) headersView() string {
|
|||||||
return lipgloss.JoinHorizontal(lipgloss.Left, s...)
|
return lipgloss.JoinHorizontal(lipgloss.Left, s...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Model) columnNeedsScrolling(columnIdxToCheck int) bool {
|
||||||
|
for rowIdx := m.start; rowIdx < m.end; rowIdx++ {
|
||||||
|
for columnIdx, value := range m.rows[rowIdx] {
|
||||||
|
if columnIdx == columnIdxToCheck && runewidth.StringWidth(value) > m.cols[columnIdx].Width {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Model) renderRow(rowID int) string {
|
func (m *Model) renderRow(rowID int) string {
|
||||||
isRowSelected := rowID == m.cursor
|
isRowSelected := rowID == m.cursor
|
||||||
var s = make([]string, 0, len(m.cols))
|
var s = make([]string, 0, len(m.cols))
|
||||||
@ -491,7 +502,7 @@ func (m *Model) renderRow(rowID int) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var renderedCell string
|
var renderedCell string
|
||||||
if i == m.ColIndex(m.hcol) && m.hcursor > 0 {
|
if m.columnNeedsScrolling(i) && m.hcursor > 0 {
|
||||||
renderedCell = style.Render(runewidth.Truncate(runewidth.TruncateLeft(value, m.hcursor, "…"), m.cols[i].Width, "…"))
|
renderedCell = style.Render(runewidth.Truncate(runewidth.TruncateLeft(value, m.hcursor, "…"), m.cols[i].Width, "…"))
|
||||||
} else {
|
} else {
|
||||||
renderedCell = style.Render(runewidth.Truncate(value, m.cols[i].Width, "…"))
|
renderedCell = style.Render(runewidth.Truncate(value, m.cols[i].Width, "…"))
|
||||||
|
Loading…
Reference in New Issue
Block a user