From 4cda4a722c380a39ec64db9f7adb7178ddf32d47 Mon Sep 17 00:00:00 2001 From: Brandon Fulljames Date: Wed, 29 Mar 2023 00:04:57 +0900 Subject: [PATCH] Don't reset the cache on every single update (#149) --- table/pagination.go | 6 ++++-- table/update.go | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/table/pagination.go b/table/pagination.go index 9300343..6fce9b5 100644 --- a/table/pagination.go +++ b/table/pagination.go @@ -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 diff --git a/table/update.go b/table/update.go index a34dd54..75998de 100644 --- a/table/update.go +++ b/table/update.go @@ -101,6 +101,7 @@ func (m *Model) handleKeypress(msg tea.KeyMsg) { } if key.Matches(msg, m.keyMap.FilterClear) { + m.visibleRowCacheUpdated = false m.filterTextInput.Reset() } @@ -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)