Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display area slides after pagenation enabled while list runnning. #405

Open
tbistr opened this issue Aug 9, 2023 · 3 comments · May be fixed by #406
Open

Display area slides after pagenation enabled while list runnning. #405

tbistr opened this issue Aug 9, 2023 · 3 comments · May be fixed by #406

Comments

@tbistr
Copy link

tbistr commented Aug 9, 2023

Describe the bug
I added items to list while list model running.
Then, display area slides 1 line to upper.
Selected item (or once selected items) is displayed properly.

Setup
Please complete the following information along with version numbers, if applicable.

  • WSL on Windows11
  • fish and bash
  • Windows terminal
  • en_US.UTF-8

To Reproduce
I little modify bubbletea/example/list-sample/main.go.
This program appends items each 1 seccond.
When items overflow a page, the display area slides.

Source Code
This not run on go playground.
https://go.dev/play/p/RLjPz27-lxx

Expected behavior
Display area will not slide, and index will saved each additions.

Screenshots
list_bug

@tbistr
Copy link
Author

tbistr commented Aug 9, 2023

additional comments

  • I think list.AppendItems API may be needed for efficiency.
  • Is the list module assumed that able to append items additionally by design? (what use cases does SetItems API envision?)

@naglis
Copy link
Contributor

naglis commented Aug 10, 2023

IIUC there is a bug here when SetItems() (or other method which modifies items and calls updatePagination()) would result in the pagination being shown (or hidden, if items are being removed?), we subtract pagination height from availHeight using current paginator state and paginator's PerPage and TotalPages are only updated afterwards:

bubbles/list/list.go

Lines 745 to 751 in 95d7be5

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)
}

So, e.g. if we already have 5 items in the list and have height available for 5 items (pagination is currently not shown) and then do SetItems(...) with 6 items (which would cause pagination to be shown), we would only subtract 1 (paginationView() height when there is only one page) instead of 2 (paginationView() height when there are more pages - it has an extra margin of 1) here because paginator per page/total pages is only updated later, so we assume we have more height than we actually have.

@tbistr tbistr linked a pull request Aug 11, 2023 that will close this issue
@0xBADDCAFE
Copy link

As a workaround, it seems that setting the correct height can be achieved by executing m.list.SetHeight(m.list.Height()) after cmd := m.list.SetItems(listItems). Here, m is tea.Model, and m.list is list.Model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants