on main help sign in
fix(ui): correctly position cursor when attachments are present (#2190)

This change fixes a UI issue where the cursor is off by one line when attachments are present in the editor.

commitf87d95b8522e5def84ce3dc749411dad1a7835a9 authorAyman Bagabas <ayman.bagabas@gmail.com> dateWed 11 Feb 2026, 17:15 (8 months ago) parent8eb4dc0
1 file changed+13−21
internal/ui/model/ui.go+13−21
internal/ui/model/ui.go+13−21
@@ -1928,12 +1928,8 @@ func (m *UI) Draw(scr uv.Screen, area uv.Rectangle) *tea.Cursor {
19281928
19291929 if m.textarea.Focused() {
19301930 cur := m.textarea.Cursor()
1931− cur.X++ // Adjust for app margins
1932− cur.Y += m.layout.editor.Min.Y
1933− // Offset for attachment row if present.
1934− if len(m.attachments.List()) > 0 {
1935− cur.Y++
1936− }
1931+ cur.X++ // Adjust for app margins
1932+ cur.Y += m.layout.editor.Min.Y + 1 // Offset for attachments row
19371933 return cur
19381934 }
19391935 }
@@ -2223,7 +2219,10 @@ func (m *UI) updateSize() {
22232219
22242220 m.chat.SetSize(m.layout.main.Dx(), m.layout.main.Dy())
22252221 m.textarea.SetWidth(m.layout.editor.Dx())
2226− m.textarea.SetHeight(m.layout.editor.Dy())
2222+ // TODO: Abstract the textarea and attachments into a single editor
2223+ // component so we don't have to manually account for the attachments
2224+ // height here.
2225+ m.textarea.SetHeight(m.layout.editor.Dy() - 2) // Account for top margin/attachments and bottom margin
22272226 m.renderPills()
22282227
22292228 // Handle different app states
@@ -2375,14 +2374,6 @@ func (m *UI) generateLayout(w, h int) uiLayout {
23752374 }
23762375 }
23772376
2378− if !uiLayout.editor.Empty() {
2379− // Add editor margins 1 top and bottom
2380− if len(m.attachments.List()) == 0 {
2381− uiLayout.editor.Min.Y += 1
2382− }
2383− uiLayout.editor.Max.Y -= 1
2384− }
2385−
23862377 return uiLayout
23872378}
23882379
@@ -2686,14 +2677,15 @@ func (m *UI) randomizePlaceholders() {
26862677
26872678// renderEditorView renders the editor view with attachments if any.
26882679func (m *UI) renderEditorView(width int) string {
2689− if len(m.attachments.List()) == 0 {
2690− return m.textarea.View()
2680+ var attachmentsView string
2681+ if len(m.attachments.List()) > 0 {
2682+ attachmentsView = m.attachments.Render(width)
26912683 }
2692− return lipgloss.JoinVertical(
2693− lipgloss.Top,
2694− m.attachments.Render(width),
2684+ return strings.Join([]string{
2685+ attachmentsView,
26952686 m.textarea.View(),
2696− )
2687+ "", // margin at bottom of editor
2688+ }, "\n")
26972689}
26982690
26992691// cacheSidebarLogo renders and caches the sidebar logo at the specified width.