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 4b48a85
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions list/list.go
Original file line number Diff line number Diff line change
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,29 @@ func (m *Model) updatePagination() {
availHeight -= lipgloss.Height(m.statusView())
}
if m.showPagination {
availHeight -= lipgloss.Height(m.paginationView())
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)

paginationHeight := lipgloss.Height(m.paginationView())
if m.showPagination && 2 < paginationHeight {
availHeight += paginationDefaultHeight
availHeight -= paginationHeight
updatePages(availHeight)
}

// Restore index
Expand Down

0 comments on commit 4b48a85

Please sign in to comment.