chore(textarea): remove pointer receiver on update and view (#858)

Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>
This commit is contained in:
Christian Rocha
2025-11-10 16:10:18 -05:00
committed by GitHub
co-authored by Ayman Bagabas
parent faa17cbbd6
commit 84a82dfeee
2 changed files with 73 additions and 73 deletions
+4 -4
View File
@@ -338,7 +338,7 @@ type Model struct {
}
// New creates a new model with default settings.
func New() *Model {
func New() Model {
vp := viewport.New()
vp.KeyMap = viewport.KeyMap{}
cur := cursor.New()
@@ -369,7 +369,7 @@ func New() *Model {
m.SetHeight(defaultHeight)
m.SetWidth(defaultWidth)
return &m
return m
}
// DefaultStyles returns the default styles for focused and blurred states for
@@ -1161,7 +1161,7 @@ func (m *Model) SetHeight(h int) {
}
// Update is the Bubble Tea update loop.
func (m *Model) Update(msg tea.Msg) (*Model, tea.Cmd) {
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
if !m.focus {
m.virtualCursor.Blur()
return m, nil
@@ -1407,7 +1407,7 @@ func (m *Model) view() string {
}
// View renders the text area in its current state.
func (m *Model) View() string {
func (m Model) View() string {
// XXX: This is a workaround for the case where the viewport hasn't
// been initialized yet like during the initial render. In that case,
// we need to render the view again because Update hasn't been called
+69 -69
View File
@@ -339,7 +339,7 @@ func TestView(t *testing.T) {
tests := []struct {
name string
modelFunc func(*Model) *Model
modelFunc func(Model) Model
want want
}{
{
@@ -357,7 +357,7 @@ func TestView(t *testing.T) {
},
{
name: "single line",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetValue("the first line")
return m
@@ -377,7 +377,7 @@ func TestView(t *testing.T) {
},
{
name: "multiple lines",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetValue("the first line\nthe second line\nthe third line")
return m
@@ -397,7 +397,7 @@ func TestView(t *testing.T) {
},
{
name: "single line without line numbers",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetValue("the first line")
m.ShowLineNumbers = false
@@ -418,7 +418,7 @@ func TestView(t *testing.T) {
},
{
name: "multipline lines without line numbers",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetValue("the first line\nthe second line\nthe third line")
m.ShowLineNumbers = false
@@ -439,7 +439,7 @@ func TestView(t *testing.T) {
},
{
name: "single line and custom end of buffer character",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetValue("the first line")
m.EndOfBufferCharacter = '*'
@@ -460,7 +460,7 @@ func TestView(t *testing.T) {
},
{
name: "multiple lines and custom end of buffer character",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetValue("the first line\nthe second line\nthe third line")
m.EndOfBufferCharacter = '*'
@@ -481,7 +481,7 @@ func TestView(t *testing.T) {
},
{
name: "single line without line numbers and custom end of buffer character",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetValue("the first line")
m.ShowLineNumbers = false
m.EndOfBufferCharacter = '*'
@@ -503,7 +503,7 @@ func TestView(t *testing.T) {
},
{
name: "multiple lines without line numbers and custom end of buffer character",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetValue("the first line\nthe second line\nthe third line")
m.ShowLineNumbers = false
m.EndOfBufferCharacter = '*'
@@ -525,7 +525,7 @@ func TestView(t *testing.T) {
},
{
name: "single line and custom prompt",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetValue("the first line")
m.Prompt = "* "
@@ -546,7 +546,7 @@ func TestView(t *testing.T) {
},
{
name: "multiple lines and custom prompt",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetValue("the first line\nthe second line\nthe third line")
m.Prompt = "* "
@@ -567,7 +567,7 @@ func TestView(t *testing.T) {
},
{
name: "type single line",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
input := "foo"
m = sendString(m, input)
@@ -588,7 +588,7 @@ func TestView(t *testing.T) {
},
{
name: "type multiple lines",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
input := "foo\nbar\nbaz"
m = sendString(m, input)
@@ -609,7 +609,7 @@ func TestView(t *testing.T) {
},
{
name: "softwrap",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.ShowLineNumbers = false
m.Prompt = ""
m.SetWidth(5)
@@ -634,7 +634,7 @@ func TestView(t *testing.T) {
},
{
name: "single line character limit",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.CharLimit = 7
input := "foo bar baz"
@@ -657,7 +657,7 @@ func TestView(t *testing.T) {
},
{
name: "multiple lines character limit",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.CharLimit = 19
input := "foo bar baz\nfoo bar baz"
@@ -680,7 +680,7 @@ func TestView(t *testing.T) {
},
{
name: "set width",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetWidth(10)
input := "12"
@@ -703,7 +703,7 @@ func TestView(t *testing.T) {
},
{
name: "set width max length text minus one",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetWidth(10)
input := "123"
@@ -726,7 +726,7 @@ func TestView(t *testing.T) {
},
{
name: "set width max length text",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetWidth(10)
input := "1234"
@@ -749,7 +749,7 @@ func TestView(t *testing.T) {
},
{
name: "set width max length text plus one",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetWidth(10)
input := "12345"
@@ -772,7 +772,7 @@ func TestView(t *testing.T) {
},
{
name: "set width set max width minus one",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.MaxWidth = 10
m.SetWidth(11)
@@ -796,7 +796,7 @@ func TestView(t *testing.T) {
},
{
name: "set width set max width",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.MaxWidth = 10
m.SetWidth(11)
@@ -820,7 +820,7 @@ func TestView(t *testing.T) {
},
{
name: "set width set max width plus one",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.MaxWidth = 10
m.SetWidth(11)
@@ -844,7 +844,7 @@ func TestView(t *testing.T) {
},
{
name: "set width min width minus one",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetWidth(6)
input := "123"
@@ -867,7 +867,7 @@ func TestView(t *testing.T) {
},
{
name: "set width min width",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetWidth(7)
input := "123"
@@ -890,7 +890,7 @@ func TestView(t *testing.T) {
},
{
name: "set width min width no line numbers",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.ShowLineNumbers = false
m.SetWidth(0)
@@ -914,7 +914,7 @@ func TestView(t *testing.T) {
},
{
name: "set width min width no line numbers no prompt",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.ShowLineNumbers = false
m.Prompt = ""
m.SetWidth(0)
@@ -939,7 +939,7 @@ func TestView(t *testing.T) {
},
{
name: "set width min width plus one",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetWidth(8)
input := "123"
@@ -962,7 +962,7 @@ func TestView(t *testing.T) {
},
{
name: "set width without line numbers max length text minus one",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.ShowLineNumbers = false
m.SetWidth(6)
@@ -986,7 +986,7 @@ func TestView(t *testing.T) {
},
{
name: "set width without line numbers max length text",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.ShowLineNumbers = false
m.SetWidth(6)
@@ -1010,7 +1010,7 @@ func TestView(t *testing.T) {
},
{
name: "set width without line numbers max length text plus one",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.ShowLineNumbers = false
m.SetWidth(6)
@@ -1034,7 +1034,7 @@ func TestView(t *testing.T) {
},
{
name: "set width with style",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
s := m.Styles()
s.Focused.Base = lipgloss.NewStyle().Border(lipgloss.NormalBorder())
m.SetStyles(s)
@@ -1064,7 +1064,7 @@ func TestView(t *testing.T) {
},
{
name: "set width with style max width minus one",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
s := m.Styles()
s.Focused.Base = lipgloss.NewStyle().Border(lipgloss.NormalBorder())
m.SetStyles(s)
@@ -1094,7 +1094,7 @@ func TestView(t *testing.T) {
},
{
name: "set width with style max width",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
s := m.Styles()
s.Focused.Base = lipgloss.NewStyle().Border(lipgloss.NormalBorder())
m.SetStyles(s)
@@ -1124,7 +1124,7 @@ func TestView(t *testing.T) {
},
{
name: "set width with style max width plus one",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
s := m.Styles()
s.Focused.Base = lipgloss.NewStyle().Border(lipgloss.NormalBorder())
m.SetStyles(s)
@@ -1154,7 +1154,7 @@ func TestView(t *testing.T) {
},
{
name: "set width without line numbers with style",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
s := m.Styles()
s.Focused.Base = lipgloss.NewStyle().Border(lipgloss.NormalBorder())
m.SetStyles(s)
@@ -1185,7 +1185,7 @@ func TestView(t *testing.T) {
},
{
name: "set width without line numbers with style max width minus one",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
s := m.Styles()
s.Focused.Base = lipgloss.NewStyle().Border(lipgloss.NormalBorder())
m.SetStyles(s)
@@ -1216,7 +1216,7 @@ func TestView(t *testing.T) {
},
{
name: "set width without line numbers with style max width",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
s := m.Styles()
s.Focused.Base = lipgloss.NewStyle().Border(lipgloss.NormalBorder())
m.SetStyles(s)
@@ -1247,7 +1247,7 @@ func TestView(t *testing.T) {
},
{
name: "set width without line numbers with style max width plus one",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
s := m.Styles()
s.Focused.Base = lipgloss.NewStyle().Border(lipgloss.NormalBorder())
m.SetStyles(s)
@@ -1278,7 +1278,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder min width",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetWidth(0)
return m
@@ -1296,7 +1296,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder single line",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "placeholder the first line"
m.ShowLineNumbers = false
@@ -1315,7 +1315,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder multiple lines",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "placeholder the first line\nplaceholder the second line\nplaceholder the third line"
m.ShowLineNumbers = false
@@ -1334,7 +1334,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder single line with line numbers",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "placeholder the first line"
m.ShowLineNumbers = true
@@ -1353,7 +1353,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder multiple lines with line numbers",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "placeholder the first line\nplaceholder the second line\nplaceholder the third line"
m.ShowLineNumbers = true
@@ -1372,7 +1372,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder single line with end of buffer character",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "placeholder the first line"
m.ShowLineNumbers = false
m.EndOfBufferCharacter = '*'
@@ -1392,7 +1392,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder multiple lines with with end of buffer character",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "placeholder the first line\nplaceholder the second line\nplaceholder the third line"
m.ShowLineNumbers = false
m.EndOfBufferCharacter = '*'
@@ -1412,7 +1412,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder single line with line numbers and end of buffer character",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "placeholder the first line"
m.ShowLineNumbers = true
m.EndOfBufferCharacter = '*'
@@ -1432,7 +1432,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder multiple lines with line numbers and end of buffer character",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "placeholder the first line\nplaceholder the second line\nplaceholder the third line"
m.ShowLineNumbers = true
m.EndOfBufferCharacter = '*'
@@ -1452,7 +1452,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder single line that is longer than max width",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "placeholder the first line that is longer than the max width"
m.SetWidth(40)
m.ShowLineNumbers = false
@@ -1472,7 +1472,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder multiple lines that are longer than max width",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "placeholder the first line that is longer than the max width\nplaceholder the second line that is longer than the max width"
m.ShowLineNumbers = false
m.SetWidth(40)
@@ -1492,7 +1492,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder single line that is longer than max width with line numbers",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "placeholder the first line that is longer than the max width"
m.ShowLineNumbers = true
m.SetWidth(40)
@@ -1512,7 +1512,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder multiple lines that are longer than max width with line numbers",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "placeholder the first line that is longer than the max width\nplaceholder the second line that is longer than the max width"
m.ShowLineNumbers = true
m.SetWidth(40)
@@ -1532,7 +1532,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder single line that is longer than max width at limit",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "123456789012345678"
m.ShowLineNumbers = false
m.SetWidth(20)
@@ -1552,7 +1552,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder single line that is longer than max width at limit plus one",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "1234567890123456789"
m.ShowLineNumbers = false
m.SetWidth(20)
@@ -1572,7 +1572,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder single line that is longer than max width with line numbers at limit",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "12345678901234"
m.ShowLineNumbers = true
m.SetWidth(20)
@@ -1592,7 +1592,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder single line that is longer than max width with line numbers at limit plus one",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "123456789012345"
m.ShowLineNumbers = true
m.SetWidth(20)
@@ -1612,7 +1612,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder multiple lines that are longer than max width at limit",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "123456789012345678\n123456789012345678"
m.ShowLineNumbers = false
m.SetWidth(20)
@@ -1632,7 +1632,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder multiple lines that are longer than max width at limit plus one",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "1234567890123456789\n1234567890123456789"
m.ShowLineNumbers = false
m.SetWidth(20)
@@ -1652,7 +1652,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder multiple lines that are longer than max width with line numbers at limit",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "12345678901234\n12345678901234"
m.ShowLineNumbers = true
m.SetWidth(20)
@@ -1672,7 +1672,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder multiple lines that are longer than max width with line numbers at limit plus one",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "123456789012345\n123456789012345"
m.ShowLineNumbers = true
m.SetWidth(20)
@@ -1692,7 +1692,7 @@ func TestView(t *testing.T) {
},
{
name: "placeholder chinese character",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.Placeholder = "输入消息..."
m.ShowLineNumbers = true
m.SetWidth(20)
@@ -1712,7 +1712,7 @@ func TestView(t *testing.T) {
},
{
name: "page up moves to beginning when near top",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.ShowLineNumbers = true
m.SetHeight(4)
m.SetWidth(20)
@@ -1743,7 +1743,7 @@ func TestView(t *testing.T) {
},
{
name: "page up snaps to first visible line when not on it",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.ShowLineNumbers = true
m.SetHeight(4)
m.SetWidth(20)
@@ -1774,7 +1774,7 @@ func TestView(t *testing.T) {
},
{
name: "page up moves up by full page when on first visible line",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.ShowLineNumbers = true
m.SetHeight(3)
m.SetWidth(20)
@@ -1804,7 +1804,7 @@ func TestView(t *testing.T) {
},
{
name: "page down moves to end when near bottom",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetHeight(3)
m.SetWidth(20)
@@ -1833,7 +1833,7 @@ func TestView(t *testing.T) {
},
{
name: "page down snaps to last visible line when not on it",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetHeight(3)
m.SetWidth(20)
@@ -1862,7 +1862,7 @@ func TestView(t *testing.T) {
},
{
name: "page down moves down by full page when on last visible line",
modelFunc: func(m *Model) *Model {
modelFunc: func(m Model) Model {
m.SetHeight(3)
m.SetWidth(20)
@@ -1974,7 +1974,7 @@ func TestWord(t *testing.T) {
})
}
func newTextArea() *Model {
func newTextArea() Model {
textarea := New()
textarea.Prompt = "> "
@@ -1991,7 +1991,7 @@ func keyPress(key rune) tea.Msg {
return tea.KeyPressMsg{Code: key, Text: string(key)}
}
func sendString(m *Model, str string) *Model {
func sendString(m Model, str string) Model {
for _, k := range []rune(str) {
m, _ = m.Update(keyPress(k))
}