@@ -9,6 +9,8 @@ import (
99 "github.com/charmbracelet/lipgloss/v2"
1010)
1111
12+const maxCompletionsHeight = 10
13+
1214type Completion struct {
1315 Title string // The title of the completion item
1416 Value any // The value of the completion item
@@ -43,7 +45,7 @@ type Completions interface {
4345type completionsCmp struct {
4446 width int
4547 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
4749 y int // Y position for the completions popup
4850 open bool // Indicates if the completions are open
4951 keyMap KeyMap
@@ -150,18 +152,25 @@ func (c *completionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
150152 if !c.open {
151153 return c, nil // If completions are not open, do nothing
152154 }
153− cmd := c.list.Filter(msg.Query)
154− c.height = max(min(10, len(c.list.Items())), 1)
155− return c, tea.Batch(
156− cmd,
157− c.list.SetSize(c.width, c.height),
158− )
155+ var cmds []tea.Cmd
156+ cmds = append(cmds, c.list.Filter(msg.Query))
157+ itemsLen := len(c.list.Items())
158+ c.height = max(min(maxCompletionsHeight, itemsLen), 1)
159+ cmds = append(cmds, c.list.SetSize(c.width, c.height))
160+ if itemsLen == 0 {
161+ // Close completions if no items match the query
162+ cmds = append(cmds, util.CmdHandler(CloseCompletionsMsg{}))
163+ }
164+ return c, tea.Batch(cmds...)
159165 }
160166 return c, nil
161167}
162168
163169// View implements Completions.
164170func (c *completionsCmp) View() string {
171+ if !c.open {
172+ return ""
173+ }
165174 if len(c.list.Items()) == 0 {
166175 return c.style().Render("No completions found")
167176 }