From 798eaeb6946166207d9e8a6edd5f2752a508244c Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Tue, 25 Feb 2025 14:40:09 -0500 Subject: [PATCH] chore(input,textarea): return nil for cursors when using virtual cursors --- textarea/textarea.go | 12 ++++++++---- textinput/textinput.go | 15 ++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/textarea/textarea.go b/textarea/textarea.go index 437e3829..b54306b0 100644 --- a/textarea/textarea.go +++ b/textarea/textarea.go @@ -1418,7 +1418,10 @@ func Blink() tea.Msg { } // Cursor returns a [tea.Cursor] for rendering a real cursor in a Bubble Tea -// program. +// program. This requires that [Model.VirtualCursor] is set to false. +// +// Note that you will almost certainly also need to adjust the offset cursor +// position per the textarea's per the textarea's position in the terminal. // // Example: // @@ -1428,12 +1431,13 @@ func Blink() tea.Msg { // f.Cursor.Position.X += offsetX // f.Cursor.Position.Y += offsetY // -// Note that you will almost certainly also need to adjust the offset -// position of the textarea to properly set the cursor position. -// // If you're using a real cursor, you should also set [Model.VirtualCursor] to // false. func (m Model) Cursor() *tea.Cursor { + if m.VirtualCursor { + return nil + } + lineInfo := m.LineInfo() w := lipgloss.Width baseStyle := m.activeStyle().Base diff --git a/textinput/textinput.go b/textinput/textinput.go index aa13acbb..52194e7d 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -867,7 +867,10 @@ func (m Model) validate(v []rune) error { } // Cursor returns a [tea.Cursor] for rendering a real cursor in a Bubble Tea -// program. +// program. This requires that [Model.VirtualCursor] is set to false. +// +// Note that you will almost certainly also need to adjust the offset cursor +// position per the textarea's per the textarea's position in the terminal. // // Example: // @@ -876,13 +879,11 @@ func (m Model) validate(v []rune) error { // f.Cursor = m.textarea.Cursor() // f.Cursor.Position.X += offsetX // f.Cursor.Position.Y += offsetY -// -// Note that you will almost certainly also need to adjust the offset -// position of the textarea to properly set the cursor position. -// -// If you're using a real cursor, you should also set [Model.VirtualCursor] to -// false. func (m Model) Cursor() *tea.Cursor { + if m.VirtualCursor { + return nil + } + w := lipgloss.Width xOffset := m.Position() +