on main help sign in
fix(ui): hide cursor when editor is not visible
a52e030Ayman Bagabas
internal/ui/model/ui.go+17−8
@@ -386,19 +386,28 @@ func (m *UI) Draw(scr uv.Screen, area uv.Rectangle) {
386 }
386 }
387}
387}
388
388
389+// Cursor returns the cursor position and properties for the UI model. It
390+// returns nil if the cursor should not be shown.
391+func (m *UI) Cursor() *tea.Cursor {
392+ if m.layout.editor.Dy() <= 0 {
393+ // Don't show cursor if editor is not visible
394+ return nil
395+ }
396+ if m.focus == uiFocusEditor && m.textarea.Focused() {
397+ cur := m.textarea.Cursor()
398+ cur.X++ // Adjust for app margins
399+ cur.Y += m.layout.editor.Min.Y
400+ return cur
401+ }
402+ return nil
403+}
404+
389// View renders the UI model's view.
405// View renders the UI model's view.
390func (m *UI) View() tea.View {
406func (m *UI) View() tea.View {
391 var v tea.View
407 var v tea.View
392 v.AltScreen = true
408 v.AltScreen = true
393 v.BackgroundColor = m.com.Styles.Background
409 v.BackgroundColor = m.com.Styles.Background
394−
395− layout := generateLayout(m, m.width, m.height)
396− if m.focus == uiFocusEditor && m.textarea.Focused() {
397− cur := m.textarea.Cursor()
398− cur.X++ // Adjust for app margins
399− cur.Y += layout.editor.Min.Y
400− v.Cursor = cur
410+ v.Cursor = m.Cursor()
401− }
402
411
403 // TODO: Switch to lipgloss.Canvas when available
412 // TODO: Switch to lipgloss.Canvas when available
404 canvas := uv.NewScreenBuffer(m.width, m.height)
413 canvas := uv.NewScreenBuffer(m.width, m.height)