diff --git a/internal/tui/components/chat/editor/editor.go b/internal/tui/components/chat/editor/editor.go index 55a5e7525a430039b314cd810cb94856185cf5af..7f06e69a388e10a49cbb792d0f4b8d231613eb3b 100644 --- a/internal/tui/components/chat/editor/editor.go +++ b/internal/tui/components/chat/editor/editor.go @@ -161,10 +161,19 @@ func (m *editorCmp) send() tea.Cmd { ) } +func (m *editorCmp) repositionCompletions() tea.Msg { + cur := m.textarea.Cursor() + x := cur.X + m.x // adjust for padding + y := cur.Y + m.y + 1 + return completions.RepositionCompletionsMsg{X: x, Y: y} +} + func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd var cmds []tea.Cmd switch msg := msg.(type) { + case tea.WindowSizeMsg: + return m, m.repositionCompletions case filepicker.FilePickedMsg: if len(m.attachments) >= maxAttachments { return m, util.ReportError(fmt.Errorf("cannot add more than %d images", maxAttachments)) diff --git a/internal/tui/components/completions/completions.go b/internal/tui/components/completions/completions.go index e82dff1816f53e1467d3c18478eeeee9dbfbb856..fae46d70d806f6847eeb40ea9b727da1671145d9 100644 --- a/internal/tui/components/completions/completions.go +++ b/internal/tui/components/completions/completions.go @@ -29,6 +29,10 @@ type FilterCompletionsMsg struct { Reopen bool } +type RepositionCompletionsMsg struct { + X, Y int +} + type CompletionsClosedMsg struct{} type CompletionsOpenedMsg struct{} @@ -52,6 +56,7 @@ type Completions interface { type completionsCmp struct { wWidth int // The window width + wHeight int // The window height width int lastWidth int height int // Height of the completions component` @@ -88,7 +93,7 @@ func New() Completions { ) return &completionsCmp{ width: 0, - height: 0, + height: maxCompletionsHeight, list: l, query: "", keyMap: completionsKeyMap, @@ -107,8 +112,7 @@ func (c *completionsCmp) Init() tea.Cmd { func (c *completionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.WindowSizeMsg: - c.wWidth = msg.Width - c.height = min(msg.Height-c.y, 15) + c.wWidth, c.wHeight = msg.Width, msg.Height return c, nil case tea.KeyPressMsg: switch { @@ -159,6 +163,8 @@ func (c *completionsCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case key.Matches(msg, c.keyMap.Cancel): return c, util.CmdHandler(CloseCompletionsMsg{}) } + case RepositionCompletionsMsg: + c.x, c.y = msg.X, msg.Y case CloseCompletionsMsg: c.open = false return c, util.CmdHandler(CompletionsClosedMsg{}) diff --git a/internal/tui/page/chat/chat.go b/internal/tui/page/chat/chat.go index 0d28f13f3ca0a42c9ae15612f21678cdeb8f4bf2..5cb6c31f9f5be5554280ef7deba16bd82eb2395d 100644 --- a/internal/tui/page/chat/chat.go +++ b/internal/tui/page/chat/chat.go @@ -165,7 +165,9 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) { p.keyboardEnhancements = msg return p, nil case tea.WindowSizeMsg: - return p, p.SetSize(msg.Width, msg.Height) + u, cmd := p.editor.Update(msg) + p.editor = u.(editor.Editor) + return p, tea.Batch(p.SetSize(msg.Width, msg.Height), cmd) case CancelTimerExpiredMsg: p.isCanceling = false return p, nil diff --git a/internal/tui/tui.go b/internal/tui/tui.go index 16112401290f2e8e6765d7f7ee55b54672190bd7..1cdc0c38243da39b2bd8c8eb276beea78f1dd37f 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -116,7 +116,7 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return a, a.handleWindowResize(msg.Width, msg.Height) // Completions messages - case completions.OpenCompletionsMsg, completions.FilterCompletionsMsg, completions.CloseCompletionsMsg: + case completions.OpenCompletionsMsg, completions.FilterCompletionsMsg, completions.CloseCompletionsMsg, completions.RepositionCompletionsMsg: u, completionCmd := a.completions.Update(msg) a.completions = u.(completions.Completions) return a, completionCmd