diff --git a/ui/suggestions/suggestions.go b/ui/suggestions/suggestions.go index c813b57..d28dd15 100644 --- a/ui/suggestions/suggestions.go +++ b/ui/suggestions/suggestions.go @@ -60,8 +60,9 @@ func New() Model { ), } return Model{ - cursor: 0, - keyMap: keyBindings, + cursor: 0, + keyMap: keyBindings, + suggestionId: uuid.New(), } } @@ -77,6 +78,10 @@ func SuggestCmd(cmd string, suggestionId uuid.UUID) tea.Cmd { } } +func (m *Model) Init(command string) tea.Cmd { + return SuggestCmd(command, m.suggestionId) +} + func (m *Model) cursorUp() { m.cursor = utils.Clamp(m.cursor-1, 0, len(m.suggestions)-1) } diff --git a/ui/ui.go b/ui/ui.go index b96a45e..bc373a0 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -3,7 +3,6 @@ package ui import ( "fmt" "runtime" - "strings" "github.com/charmbracelet/bubbles/cursor" "github.com/charmbracelet/bubbles/textinput" @@ -33,7 +32,7 @@ const ( func Start(startingContent string) model { ti := textinput.New() - ti.SetValue(strings.TrimSpace(startingContent)) + ti.SetValue(startingContent) ti.Cursor.Style = lipgloss.NewStyle().Foreground(theme.CursorForeground) ti.Focus() sug := suggestions.New() @@ -42,7 +41,7 @@ func Start(startingContent string) model { } func (m model) Init() tea.Cmd { - return textinput.Blink + return tea.Batch(textinput.Blink, m.suggestions.Init(m.textInput.Value())) } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {