@@ -150,18 +150,25 @@ func (c *completionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
150 if !c.open {
150 if !c.open {
151 return c, nil // If completions are not open, do nothing
151 return c, nil // If completions are not open, do nothing
153− cmd := c.list.Filter(msg.Query)
154+ cmds = append(cmds, c.list.Filter(msg.Query))
155+ itemsLen := len(c.list.Items())
154− c.height = max(min(10, len(c.list.Items())), 1)
156+ c.height = max(min(10, itemsLen), 1)
155− return c, tea.Batch(
157− c.list.SetSize(c.width, c.height),
157+ cmds = append(cmds, c.list.SetSize(c.width, c.height))
158− )
158+ if itemsLen == 0 {
159+ // Close completions if no items match the query
160+ cmds = append(cmds, util.CmdHandler(CloseCompletionsMsg{}))
162+ return c, tea.Batch(cmds...)
160 return c, nil
164 return c, nil
163// View implements Completions.
167// View implements Completions.
164func (c *completionsCmp) View() string {
168func (c *completionsCmp) View() string {
165 if len(c.list.Items()) == 0 {
172 if len(c.list.Items()) == 0 {
166 return c.style().Render("No completions found")
173 return c.style().Render("No completions found")