mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-16 01:43:21 +00:00
fix(textarea): use pointer receiver for Model methods
This commit is contained in:
+10
-13
@@ -334,7 +334,7 @@ type Model struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new model with default settings.
|
// New creates a new model with default settings.
|
||||||
func New() Model {
|
func New() *Model {
|
||||||
vp := viewport.New()
|
vp := viewport.New()
|
||||||
vp.KeyMap = viewport.KeyMap{}
|
vp.KeyMap = viewport.KeyMap{}
|
||||||
cur := cursor.New()
|
cur := cursor.New()
|
||||||
@@ -365,7 +365,7 @@ func New() Model {
|
|||||||
m.SetHeight(defaultHeight)
|
m.SetHeight(defaultHeight)
|
||||||
m.SetWidth(defaultWidth)
|
m.SetWidth(defaultWidth)
|
||||||
|
|
||||||
return m
|
return &m
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultStyles returns the default styles for focused and blurred states for
|
// 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.
|
// 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 {
|
if !m.focus {
|
||||||
m.virtualCursor.Blur()
|
m.virtualCursor.Blur()
|
||||||
return m, nil
|
return m, nil
|
||||||
@@ -1358,16 +1358,13 @@ func (m *Model) view() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// View renders the text area in its current state.
|
// View renders the text area in its current state.
|
||||||
func (m Model) View() string {
|
func (m *Model) View() string {
|
||||||
view := strings.TrimSpace(m.viewport.View())
|
// XXX: This is a workaround for the case where the viewport hasn't
|
||||||
if view == "" {
|
// been initialized yet like during the initial render. In that case,
|
||||||
// XXX: This is a workaround for the case where the viewport hasn't
|
// we need to render the view again because Update hasn't been called
|
||||||
// been initialized yet like during the initial render. In that case,
|
// yet to set the content of the viewport.
|
||||||
// we need to render the view again because Update hasn't been called
|
m.viewport.SetContent(m.view())
|
||||||
// yet to set the content of the viewport.
|
view := m.viewport.View()
|
||||||
m.viewport.SetContent(m.view())
|
|
||||||
view = m.viewport.View()
|
|
||||||
}
|
|
||||||
styles := m.activeStyle()
|
styles := m.activeStyle()
|
||||||
return styles.Base.Render(view)
|
return styles.Base.Render(view)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user