Skip to content

Commit

Permalink
remove renderedlines from table struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Jager,Petar authored and maaslalani committed Dec 1, 2022
1 parent 7392b36 commit 94252ef
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 94252ef

Please sign in to comment.