@@ -150,18 +150,25 @@ func (c *completionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
150150 if !c.open {
151151 return c, nil // If completions are not open, do nothing
152152 }
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− )
153+ var cmds []tea.Cmd
154+ cmds = append(cmds, c.list.Filter(msg.Query))
155+ itemsLen := len(c.list.Items())
156+ c.height = max(min(10, itemsLen), 1)
157+ cmds = append(cmds, c.list.SetSize(c.width, c.height))
158+ if itemsLen == 0 {
159+ // Close completions if no items match the query
160+ cmds = append(cmds, util.CmdHandler(CloseCompletionsMsg{}))
161+ }
162+ return c, tea.Batch(cmds...)
159163 }
160164 return c, nil
161165}
162166
163167// View implements Completions.
164168func (c *completionsCmp) View() string {
169+ if !c.open {
170+ return ""
171+ }
165172 if len(c.list.Items()) == 0 {
166173 return c.style().Render("No completions found")
167174 }