on main help sign in
Merge pull request #134 from charmbracelet/comp-padding
8ff604fKujtim Hoxha
internal/tui/components/chat/editor/editor.go+3−2
@@ -361,8 +361,9 @@ func (m *editorCmp) startCompletions() tea.Msg {
361 })
361 })
362 }
362 }
363
363
364− x := m.textarea.Cursor().X + m.x + 1
364+ cur := m.textarea.Cursor()
365− y := m.textarea.Cursor().Y + m.y + 1
365+ x := cur.X + m.x // adjust for padding
366+ y := cur.Y + m.y + 1
366 return completions.OpenCompletionsMsg{
367 return completions.OpenCompletionsMsg{
367 Completions: completionItems,
368 Completions: completionItems,
368 X: x,
369 X: x,
internal/tui/components/completions/completions.go+16−7
@@ -9,6 +9,8 @@ import (
9 "github.com/charmbracelet/lipgloss/v2"
9 "github.com/charmbracelet/lipgloss/v2"
10)
10)
11
11
12+const maxCompletionsHeight = 10
13+
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 {
44 width int
46 width int
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
152 }
154 }
155+ var cmds []tea.Cmd
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)
156− cmd,
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{}))
163+ }
164+ return c, tea.Batch(cmds...)
159 }
165 }
160 return c, nil
166 return c, nil
161}
167}
162
168
163// View implements Completions.
169// View implements Completions.
164func (c *completionsCmp) View() string {
170func (c *completionsCmp) View() string {
171+ if !c.open {
172+ return ""
173+ }
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")
167 }
176 }