From a52e0306c3603b969daed15a59cc88683fac9e8c Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 2 Dec 2025 11:56:58 -0500 Subject: [PATCH] fix(ui): hide cursor when editor is not visible --- internal/ui/model/ui.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/internal/ui/model/ui.go b/internal/ui/model/ui.go index 7a3b2847fb3b8c659d69fe4645cd1228ee881c88..ba2cdcf9ce92291c68f07b142501a2c0688f44f1 100644 --- a/internal/ui/model/ui.go +++ b/internal/ui/model/ui.go @@ -386,19 +386,28 @@ func (m *UI) Draw(scr uv.Screen, area uv.Rectangle) { } } +// Cursor returns the cursor position and properties for the UI model. It +// returns nil if the cursor should not be shown. +func (m *UI) Cursor() *tea.Cursor { + if m.layout.editor.Dy() <= 0 { + // Don't show cursor if editor is not visible + return nil + } + if m.focus == uiFocusEditor && m.textarea.Focused() { + cur := m.textarea.Cursor() + cur.X++ // Adjust for app margins + cur.Y += m.layout.editor.Min.Y + return cur + } + return nil +} + // View renders the UI model's view. func (m *UI) View() tea.View { var v tea.View v.AltScreen = true v.BackgroundColor = m.com.Styles.Background - - layout := generateLayout(m, m.width, m.height) - if m.focus == uiFocusEditor && m.textarea.Focused() { - cur := m.textarea.Cursor() - cur.X++ // Adjust for app margins - cur.Y += layout.editor.Min.Y - v.Cursor = cur - } + v.Cursor = m.Cursor() // TODO: Switch to lipgloss.Canvas when available canvas := uv.NewScreenBuffer(m.width, m.height)