Skip to content

Commit

Permalink
Don't reset the cache on every single update (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evertras committed Mar 28, 2023
1 parent c270555 commit 4cda4a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 4 additions & 2 deletions table/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ func (m *Model) CurrentPage() int {

// MaxPages returns the maximum number of pages that are visible.
func (m *Model) MaxPages() int {
if m.pageSize == 0 || len(m.GetVisibleRows()) == 0 {
totalRows := len(m.GetVisibleRows())

if m.pageSize == 0 || totalRows == 0 {
return 1
}

return (len(m.GetVisibleRows())-1)/m.pageSize + 1
return (totalRows-1)/m.pageSize + 1
}

// TotalRows returns the current total row count of the table. If the table is
Expand Down
3 changes: 1 addition & 2 deletions table/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (m *Model) handleKeypress(msg tea.KeyMsg) {
}

if key.Matches(msg, m.keyMap.FilterClear) {
m.visibleRowCacheUpdated = false
m.filterTextInput.Reset()
}

Expand Down Expand Up @@ -128,8 +129,6 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
return m, nil
}

m.visibleRowCacheUpdated = false

if m.filterTextInput.Focused() {
var cmd tea.Cmd
m, cmd = m.updateFilterTextInput(msg)
Expand Down

0 comments on commit 4cda4a7

Please sign in to comment.