Update pagination according to the amount of items for the current state.
()
| 639 | |
| 640 | // Update pagination according to the amount of items for the current state. |
| 641 | func (m *Model) updatePagination() { |
| 642 | index := m.Index() |
| 643 | availHeight := m.height |
| 644 | |
| 645 | if m.showTitle || (m.showFilter && m.filteringEnabled) { |
| 646 | availHeight -= lipgloss.Height(m.titleView()) |
| 647 | } |
| 648 | if m.showStatusBar { |
| 649 | availHeight -= lipgloss.Height(m.statusView()) |
| 650 | } |
| 651 | if m.showPagination { |
| 652 | availHeight -= lipgloss.Height(m.paginationView()) |
| 653 | } |
| 654 | if m.showHelp { |
| 655 | availHeight -= lipgloss.Height(m.helpView()) |
| 656 | } |
| 657 | |
| 658 | m.Paginator.PerPage = max(1, availHeight/(m.delegate.Height()+m.delegate.Spacing())) |
| 659 | |
| 660 | if pages := len(m.VisibleItems()); pages < 1 { |
| 661 | m.Paginator.SetTotalPages(1) |
| 662 | } else { |
| 663 | m.Paginator.SetTotalPages(pages) |
| 664 | } |
| 665 | |
| 666 | // Restore index |
| 667 | m.Paginator.Page = index / m.Paginator.PerPage |
| 668 | m.cursor = index % m.Paginator.PerPage |
| 669 | |
| 670 | // Make sure the page stays in bounds |
| 671 | if m.Paginator.Page >= m.Paginator.TotalPages-1 { |
| 672 | m.Paginator.Page = max(0, m.Paginator.TotalPages-1) |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | func (m *Model) hideStatusMessage() { |
| 677 | m.statusMessage = "" |
no test coverage detected