From 237dbde92cc514b2b247887c8fd29b0c9cb774aa Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Thu, 10 Jul 2025 15:25:52 -0400 Subject: [PATCH 1/3] fix(tui): editor: position completions correctly and account for padding --- internal/tui/components/chat/editor/editor.go | 5 +++-- internal/tui/components/completions/completions.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/tui/components/chat/editor/editor.go b/internal/tui/components/chat/editor/editor.go index 2185715c813dbdcb288bddde0fe70d63046cf731..67ba67f5e6c40f16a89f7bc4fe1b6932c9989754 100644 --- a/internal/tui/components/chat/editor/editor.go +++ b/internal/tui/components/chat/editor/editor.go @@ -361,8 +361,9 @@ func (m *editorCmp) startCompletions() tea.Msg { }) } - x := m.textarea.Cursor().X + m.x + 1 - y := m.textarea.Cursor().Y + m.y + 1 + cur := m.textarea.Cursor() + x := cur.X + m.x // adjust for padding + y := cur.Y + m.y + 1 return completions.OpenCompletionsMsg{ Completions: completionItems, X: x, diff --git a/internal/tui/components/completions/completions.go b/internal/tui/components/completions/completions.go index 29ea86365e9f1532eab3aa1a61214ef74b7f4a05..6409f4bc96f59349046891d872994393550c65ba 100644 --- a/internal/tui/components/completions/completions.go +++ b/internal/tui/components/completions/completions.go @@ -43,7 +43,7 @@ type Completions interface { type completionsCmp struct { width int height int // Height of the completions component` - x int // X position for the completions popup\ + x int // X position for the completions popup y int // Y position for the completions popup open bool // Indicates if the completions are open keyMap KeyMap From 055b30f04e9121a60b1628169d4bb4fd6db0d0c8 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Thu, 10 Jul 2025 17:13:11 -0400 Subject: [PATCH 2/3] fix(tui): completions: close when no items match query This simply closes the completions component when there are no items matching the query. --- .../tui/components/completions/completions.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/internal/tui/components/completions/completions.go b/internal/tui/components/completions/completions.go index 6409f4bc96f59349046891d872994393550c65ba..e9c410d37a91ac245b7766cb7b1469dd4b421eda 100644 --- a/internal/tui/components/completions/completions.go +++ b/internal/tui/components/completions/completions.go @@ -150,18 +150,25 @@ func (c *completionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if !c.open { return c, nil // If completions are not open, do nothing } - cmd := c.list.Filter(msg.Query) - c.height = max(min(10, len(c.list.Items())), 1) - return c, tea.Batch( - cmd, - c.list.SetSize(c.width, c.height), - ) + var cmds []tea.Cmd + cmds = append(cmds, c.list.Filter(msg.Query)) + itemsLen := len(c.list.Items()) + c.height = max(min(10, itemsLen), 1) + cmds = append(cmds, c.list.SetSize(c.width, c.height)) + if itemsLen == 0 { + // Close completions if no items match the query + cmds = append(cmds, util.CmdHandler(CloseCompletionsMsg{})) + } + return c, tea.Batch(cmds...) } return c, nil } // View implements Completions. func (c *completionsCmp) View() string { + if !c.open { + return "" + } if len(c.list.Items()) == 0 { return c.style().Render("No completions found") } From 88077377e176c4940249502e4680d12c4e5c5aa3 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Thu, 10 Jul 2025 21:33:59 -0400 Subject: [PATCH 3/3] chore(tui/completions): pull out magic number --- internal/tui/components/completions/completions.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/tui/components/completions/completions.go b/internal/tui/components/completions/completions.go index e9c410d37a91ac245b7766cb7b1469dd4b421eda..5a6bcfe92e23f38c3f40c84770a0dcc9893e59d5 100644 --- a/internal/tui/components/completions/completions.go +++ b/internal/tui/components/completions/completions.go @@ -9,6 +9,8 @@ import ( "github.com/charmbracelet/lipgloss/v2" ) +const maxCompletionsHeight = 10 + type Completion struct { Title string // The title of the completion item Value any // The value of the completion item @@ -153,7 +155,7 @@ func (c *completionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmds []tea.Cmd cmds = append(cmds, c.list.Filter(msg.Query)) itemsLen := len(c.list.Items()) - c.height = max(min(10, itemsLen), 1) + c.height = max(min(maxCompletionsHeight, itemsLen), 1) cmds = append(cmds, c.list.SetSize(c.width, c.height)) if itemsLen == 0 { // Close completions if no items match the query