Skip to content

Commit

Permalink
chore(textarea): account for margins and padding in cursor offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Jan 31, 2025
1 parent 8052fc4 commit 42b0377
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions textarea/textarea.go
Original file line number Diff line number Diff line change
Expand Up @@ -1441,8 +1441,20 @@ func Blink() tea.Msg {
func (m Model) Cursor() *tea.Cursor {
lineInfo := m.LineInfo()
w := lipgloss.Width
xOffset := lineInfo.CharOffset + w(m.promptView(0)) + w(m.lineNumberView(0, false))
yOffset := m.cursorLineNumber() - m.viewport.YOffset
baseStyle := m.activeStyle().Base

xOffset := lineInfo.CharOffset +
w(m.promptView(0)) +
w(m.lineNumberView(0, false)) +
baseStyle.GetMarginLeft() +
baseStyle.GetPaddingLeft() +
baseStyle.GetBorderLeftSize()

yOffset := m.cursorLineNumber() +
m.viewport.YOffset +
baseStyle.GetMarginTop() +
baseStyle.GetPaddingTop() +
baseStyle.GetBorderTopSize()

c := tea.NewCursor(xOffset, yOffset)
c.Blink = m.Styles.Cursor.Blink
Expand Down

0 comments on commit 42b0377

Please sign in to comment.