Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions internal/tui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes pageSize effectively ignore the configured cfg.PageSize (the initial pageSize from config will be overwritten on the first window-size event). If pageSize is meant to remain user-configurable, consider only applying the dynamic sizing when the config value is unset/default, or treating the config value as a hard override / max.

Suggested change
// 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 uses AI. Check for mistakes.
m.updateTable() // Refresh table to apply new page size
Comment on lines +379 to +380
Copy link

Copilot AI Mar 3, 2026

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.

Suggested change
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 uses AI. Check for mistakes.
Comment on lines +379 to +380
Copy link

Copilot AI Mar 3, 2026

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
}