Skip to content

Commit

Permalink
chore(input,textarea): return nil for cursors when using virtual cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Feb 25, 2025
1 parent 4491afa commit 798eaeb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
12 changes: 8 additions & 4 deletions textarea/textarea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
//
Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions textinput/textinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
//
Expand All @@ -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() +
Expand Down

0 comments on commit 798eaeb

Please sign in to comment.