Skip to content

Commit

Permalink
fix(list): fix list display area overflow.
Browse files Browse the repository at this point in the history
The number of Items per a page depend on  pagination height.
However, pagination height may changes if it enabled or disabled.
  • Loading branch information
tbistr committed Aug 11, 2023
1 parent 95d7be5 commit 0d23bcf
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions list/list.go
Expand Up @@ -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())
Expand All @@ -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
Expand Down

0 comments on commit 0d23bcf

Please sign in to comment.