From 0d23bcf7a88cccb71261d7c6e85c3310f0acc5de Mon Sep 17 00:00:00 2001 From: tbistr Date: Sat, 12 Aug 2023 02:34:55 +0900 Subject: [PATCH] fix(list): fix list display area overflow. The number of Items per a page depend on pagination height. However, pagination height may changes if it enabled or disabled. --- list/list.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/list/list.go b/list/list.go index 7b47879f..68ef144c 100644 --- a/list/list.go +++ b/list/list.go @@ -728,6 +728,7 @@ func (m *Model) updateKeybindings() { func (m *Model) updatePagination() { index := m.Index() availHeight := m.height + const paginationDefaultHeight = 1 if m.showTitle || (m.showFilter && m.filteringEnabled) { availHeight -= lipgloss.Height(m.titleView()) @@ -736,18 +737,31 @@ func (m *Model) updatePagination() { availHeight -= lipgloss.Height(m.statusView()) } if m.showPagination { - availHeight -= lipgloss.Height(m.paginationView()) + // First assume that pagination will not needed + availHeight -= paginationDefaultHeight } if m.showHelp { availHeight -= lipgloss.Height(m.helpView()) } - m.Paginator.PerPage = max(1, availHeight/(m.delegate.Height()+m.delegate.Spacing())) + updatePages := func(availHeight int) { + m.Paginator.PerPage = max(1, availHeight/(m.delegate.Height()+m.delegate.Spacing())) - if pages := len(m.VisibleItems()); pages < 1 { - m.Paginator.SetTotalPages(1) - } else { - m.Paginator.SetTotalPages(pages) + if pages := len(m.VisibleItems()); pages < 1 { + m.Paginator.SetTotalPages(1) + } else { + m.Paginator.SetTotalPages(pages) + } + } + + updatePages(availHeight) + + // If pagination is needed, recompute items alignment + paginationHeight := lipgloss.Height(m.paginationView()) + if m.showPagination && 2 < paginationHeight { + availHeight += paginationDefaultHeight + availHeight -= paginationHeight + updatePages(availHeight) } // Restore index