on main help sign in
fix(tui): completions: close when no items match query

This simply closes the completions component when there are no items matching the query.

commit055b30f04e9121a60b1628169d4bb4fd6db0d0c8 authorAyman Bagabas <ayman.bagabas@gmail.com> dateThu 10 Jul 2025, 17:13 (1 year ago) parent237dbde
1 file changed+13−6
internal/tui/components/completions/completions.go+13−6
internal/tui/components/completions/completions.go+13−6
@@ -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 }