From efdc0e8e45beac54dc3b92aea226d2cb995ac846 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Thu, 7 Aug 2025 10:45:21 -0400 Subject: [PATCH] fix(textarea): use pointer receiver for Model methods --- textarea/textarea.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/textarea/textarea.go b/textarea/textarea.go index 0e9a2a6..a4eac95 100644 --- a/textarea/textarea.go +++ b/textarea/textarea.go @@ -334,7 +334,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() @@ -365,7 +365,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 @@ -1116,7 +1116,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 @@ -1358,16 +1358,13 @@ func (m *Model) view() string { } // View renders the text area in its current state. -func (m Model) View() string { - view := strings.TrimSpace(m.viewport.View()) - if view == "" { - // 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 - // yet to set the content of the viewport. - m.viewport.SetContent(m.view()) - view = m.viewport.View() - } +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 + // yet to set the content of the viewport. + m.viewport.SetContent(m.view()) + view := m.viewport.View() styles := m.activeStyle() return styles.Base.Render(view) }