diff --git a/textarea/textarea.go b/textarea/textarea.go index 437e3829..8bfbdd96 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: // @@ -1427,13 +1430,11 @@ func Blink() tea.Msg { // 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 + } + 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() +