@@ -9,6 +9,8 @@ import (
9 "github.com/charmbracelet/lipgloss/v2"
9 "github.com/charmbracelet/lipgloss/v2"
12+const maxCompletionsHeight = 10
12type Completion struct {
14type Completion struct {
13 Title string // The title of the completion item
15 Title string // The title of the completion item
14 Value any // The value of the completion item
16 Value any // The value of the completion item
@@ -43,7 +45,7 @@ type Completions interface {
43type completionsCmp struct {
45type completionsCmp struct {
45 height int // Height of the completions component`
47 height int // Height of the completions component`
46− x int // X position for the completions popup\
48+ x int // X position for the completions popup
47 y int // Y position for the completions popup
49 y int // Y position for the completions popup
48 open bool // Indicates if the completions are open
50 open bool // Indicates if the completions are open
49 keyMap KeyMap
51 keyMap KeyMap
@@ -150,18 +152,25 @@ func (c *completionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
150 if !c.open {
152 if !c.open {
151 return c, nil // If completions are not open, do nothing
153 return c, nil // If completions are not open, do nothing
153− cmd := c.list.Filter(msg.Query)
156+ cmds = append(cmds, c.list.Filter(msg.Query))
154− c.height = max(min(10, len(c.list.Items())), 1)
157+ itemsLen := len(c.list.Items())
155− return c, tea.Batch(
158+ c.height = max(min(maxCompletionsHeight, itemsLen), 1)
157− c.list.SetSize(c.width, c.height),
159+ cmds = append(cmds, c.list.SetSize(c.width, c.height))
158− )
160+ if itemsLen == 0 {
161+ // Close completions if no items match the query
162+ cmds = append(cmds, util.CmdHandler(CloseCompletionsMsg{}))
164+ return c, tea.Batch(cmds...)
160 return c, nil
166 return c, nil
163// View implements Completions.
169// View implements Completions.
164func (c *completionsCmp) View() string {
170func (c *completionsCmp) View() string {
165 if len(c.list.Items()) == 0 {
174 if len(c.list.Items()) == 0 {
166 return c.style().Render("No completions found")
175 return c.style().Render("No completions found")