diff --git a/table/table.go b/table/table.go index 4cb0856e..c5739882 100644 --- a/table/table.go +++ b/table/table.go @@ -21,11 +21,8 @@ type Model struct { styles Styles viewport viewport.Model - renderedLines -} - -type renderedLines struct { - start, end int + start int + end int } // Row represents one line in the table. @@ -252,12 +249,12 @@ func (m *Model) UpdateViewport() { // Constant runtime, independent of number of rows in a table. // Limits the numer of renderedRows to a maximum of 2*m.viewport.Height if m.cursor >= 0 { - m.renderedLines.start = clamp(m.cursor-m.viewport.Height, 0, m.cursor) + m.start = clamp(m.cursor-m.viewport.Height, 0, m.cursor) } else { - m.renderedLines.start = 0 + m.start = 0 } - m.renderedLines.end = clamp(m.cursor+m.viewport.Height, m.cursor, len(m.rows)) - for i := m.renderedLines.start; i < m.renderedLines.end; i++ { + m.end = clamp(m.cursor+m.viewport.Height, m.cursor, len(m.rows)) + for i := m.start; i < m.end; i++ { renderedRows = append(renderedRows, m.renderRow(i)) } @@ -316,9 +313,9 @@ func (m *Model) SetCursor(n int) { func (m *Model) MoveUp(n int) { m.cursor = clamp(m.cursor-n, 0, len(m.rows)-1) switch { - case m.renderedLines.start == 0: + case m.start == 0: m.viewport.SetYOffset(clamp(m.viewport.YOffset, 0, m.cursor)) - case m.renderedLines.start < m.viewport.Height: + case m.start < m.viewport.Height: m.viewport.SetYOffset(clamp(m.viewport.YOffset+n, 0, m.cursor)) case m.viewport.YOffset >= 1: m.viewport.YOffset = clamp(m.viewport.YOffset+n, 1, m.viewport.Height) @@ -334,9 +331,9 @@ func (m *Model) MoveDown(n int) { m.UpdateViewport() switch { - case m.renderedLines.end == len(m.rows): + case m.end == len(m.rows): m.viewport.SetYOffset(clamp(m.viewport.YOffset-n, 1, m.viewport.Height)) - case m.cursor > (m.renderedLines.end-m.renderedLines.start)/2: + case m.cursor > (m.end-m.start)/2: m.viewport.SetYOffset(clamp(m.viewport.YOffset-n, 1, m.cursor)) case m.viewport.YOffset > 1: case m.cursor > m.viewport.YOffset+m.viewport.Height-1: