diff --git a/internal/tui/components/completions/completions.go b/internal/tui/components/completions/completions.go index 42c05bd9acae8fb099d5ae09c754114541b1f280..14a6b492523fe9cb41ece8f47140b94c5e49531e 100644 --- a/internal/tui/components/completions/completions.go +++ b/internal/tui/components/completions/completions.go @@ -140,7 +140,7 @@ func (c *completionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { selectedItem := *s c.list.SetSelected(selectedItem.ID()) return c, util.CmdHandler(SelectCompletionMsg{ - Value: selectedItem, + Value: selectedItem.Value(), Insert: true, }) case key.Matches(msg, c.keyMap.DownInsert): @@ -151,7 +151,7 @@ func (c *completionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { selectedItem := *s c.list.SetSelected(selectedItem.ID()) return c, util.CmdHandler(SelectCompletionMsg{ - Value: selectedItem, + Value: selectedItem.Value(), Insert: true, }) case key.Matches(msg, c.keyMap.Select): @@ -162,7 +162,7 @@ func (c *completionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { selectedItem := *s c.open = false // Close completions after selection return c, util.CmdHandler(SelectCompletionMsg{ - Value: selectedItem, + Value: selectedItem.Value(), }) case key.Matches(msg, c.keyMap.Cancel): return c, util.CmdHandler(CloseCompletionsMsg{}) @@ -272,18 +272,14 @@ func (c *completionsCmp) View() string { // listWidth returns the width of the last 10 items in the list, which is used // to determine the width of the completions popup. // Note this only works for [completionItemCmp] items. -func listWidth[T any](items []T) int { +func listWidth(items []list.CompletionItem[any]) int { var width int if len(items) == 0 { return width } for i := len(items) - 1; i >= 0 && i >= len(items)-10; i-- { - item, ok := any(items[i]).(*completionItemCmp) - if !ok { - continue - } - itemWidth := lipgloss.Width(item.text) + 2 // +2 for padding + itemWidth := lipgloss.Width(items[i].Text()) + 2 // +2 for padding width = max(width, itemWidth) } diff --git a/internal/tui/exp/list/items.go b/internal/tui/exp/list/items.go index 1c09e402352b0d354f01f551279c198c387042a0..b55c1dd723a245aa47ffdeb6a9ffb72fd9d8e27b 100644 --- a/internal/tui/exp/list/items.go +++ b/internal/tui/exp/list/items.go @@ -23,6 +23,7 @@ type CompletionItem[T any] interface { layout.Sizeable HasMatchIndexes Value() T + Text() string } type completionItemCmp[T any] struct { @@ -312,6 +313,10 @@ func (c *completionItemCmp[T]) ID() string { return c.id } +func (c *completionItemCmp[T]) Text() string { + return c.text +} + type ItemSection interface { Item layout.Sizeable