fix: suggestions should trigger on first load

Signed-off-by: cpendery <cpendery@vt.edu>
This commit is contained in:
cpendery
2023-09-18 01:49:41 -04:00
parent 4d95c56e09
commit 54fd8cbe54
2 changed files with 9 additions and 5 deletions
+7 -2
View File
@@ -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)
}
+2 -3
View File
@@ -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) {