-
-
Notifications
You must be signed in to change notification settings - Fork 10
feat: dynamically adjust page size based on terminal height #21
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -371,4 +371,11 @@ func (m *Model) resizeTable() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| h = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| m.table.SetHeight(h) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Ensure page size is at least 5 to avoid too small pages | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if h < 5 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| h = 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| m.pageSize = h // Update page size based on new height | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+375
to
+379
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Ensure page size is at least 5 to avoid too small pages | |
| if h < 5 { | |
| h = 5 | |
| } | |
| m.pageSize = h // Update page size based on new height | |
| // Compute a dynamic page size based on height, with a minimum of 5 | |
| dynamicPageSize := h | |
| if dynamicPageSize < 5 { | |
| dynamicPageSize = 5 | |
| } | |
| // If a positive PageSize is configured, respect it; otherwise use the dynamic size | |
| if m.cfg != nil && m.cfg.PageSize > 0 { | |
| m.pageSize = m.cfg.PageSize | |
| } else { | |
| m.pageSize = dynamicPageSize | |
| } |
Copilot
AI
Mar 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling m.updateTable() from resizeTable() means every tea.WindowSizeMsg will re-run applyFilter() and sortRepos() (O(n log n)) even though only the current page slice needs to change. Consider updating just the visible rows for the current page (and only re-sorting when the underlying repo list / filter / sort mode changes) to avoid unnecessary work during continuous resize events.
| m.pageSize = h // Update page size based on new height | |
| m.updateTable() // Refresh table to apply new page size | |
| // Only refresh the table when the effective page size actually changes | |
| if h != m.pageSize { | |
| m.pageSize = h // Update page size based on new height | |
| m.updateTable() // Refresh table to apply new page size | |
| } |
Copilot
AI
Mar 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pageSize can change on resize without adjusting currentPage. If pageSize increases, currentPage*m.pageSize may become out of range, and getCurrentPageRepos() will silently fall back to showing the first page while currentPage remains unchanged, leading to inconsistent pagination state (and incorrect “Page X of Y” behavior). After changing pageSize, clamp currentPage to [0, totalPages-1] (or reset it) before refreshing rows.
| m.pageSize = h // Update page size based on new height | |
| m.updateTable() // Refresh table to apply new page size | |
| m.pageSize = h // Update page size based on new height | |
| // Clamp currentPage to the valid range for the new page size to keep pagination consistent | |
| totalRows := len(m.table.Rows()) | |
| if totalRows == 0 { | |
| m.currentPage = 0 | |
| } else { | |
| totalPages := (totalRows + m.pageSize - 1) / m.pageSize | |
| if totalPages < 1 { | |
| totalPages = 1 | |
| } | |
| if m.currentPage < 0 { | |
| m.currentPage = 0 | |
| } else if m.currentPage >= totalPages { | |
| m.currentPage = totalPages - 1 | |
| } | |
| } | |
| m.updateTable() // Refresh table to apply new page size and current page |
Uh oh!
There was an error while loading. Please reload this page.