Skip to content
Merged
Show file tree
Hide file tree
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
43 changes: 32 additions & 11 deletions internal/tui/picker.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ func (i PickerItem) FilterValue() string {

// pickerModel is the bubbletea model for a fuzzy picker.
type pickerModel struct {
items []PickerItem
filtered []PickerItem
textInput textinput.Model
cursor int
selected *PickerItem
quitting bool
styles *Styles
title string
maxVisible int
scrollOffset int
items []PickerItem
filtered []PickerItem
textInput textinput.Model
cursor int
selected *PickerItem
quitting bool
styles *Styles
title string
maxVisible int
maxVisibleCap int // configured upper bound, restored on terminal grow
scrollOffset int

// Loading state
loading bool
Expand Down Expand Up @@ -66,7 +67,11 @@ func WithPickerTitle(title string) PickerOption {
// WithMaxVisible sets the maximum number of visible items.
func WithMaxVisible(n int) PickerOption {
return func(m *pickerModel) {
if n < 1 {
n = 1
}
m.maxVisible = n
m.maxVisibleCap = n
}
}

Expand Down Expand Up @@ -123,7 +128,8 @@ func newPickerModel(items []PickerItem, opts ...PickerOption) pickerModel {
textInput: ti,
styles: styles,
title: "Select an item",
maxVisible: 10,
maxVisible: 20,
Comment thread
jeremy marked this conversation as resolved.
Comment thread
jeremy marked this conversation as resolved.
maxVisibleCap: 20,
spinner: s,
loadingMsg: "Loading…",
emptyMessage: "No items found",
Expand Down Expand Up @@ -233,6 +239,21 @@ func (m pickerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

return m, textinput.Blink

case tea.WindowSizeMsg:
// Clamp maxVisible to fit the terminal: reserve lines for
// title, blank, input, blank, scroll indicator, help.
const chromeLines = 6
if avail := msg.Height - chromeLines; avail >= 1 {
m.maxVisible = min(avail, m.maxVisibleCap)
}
// Re-clamp cursor and scroll offset to the new visible window
if m.cursor >= len(m.filtered) && len(m.filtered) > 0 {
m.cursor = len(m.filtered) - 1
}
if m.cursor >= m.scrollOffset+m.maxVisible {
m.scrollOffset = m.cursor - m.maxVisible + 1
}

Comment thread
jeremy marked this conversation as resolved.
case spinner.TickMsg:
if m.loading {
var cmd tea.Cmd
Expand Down
2 changes: 1 addition & 1 deletion internal/tui/workspace/widget/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (l *List) handleFilterKey(km tea.KeyPressMsg) tea.Cmd {
func (l *List) visibleHeight() int {
h := l.height
if h <= 0 {
h = 10
h = 20
}
if l.filtering || l.filter != "" {
h--
Expand Down
Loading