mirror of
https://github.com/ivabus/pop
synced 2024-11-10 02:25:19 +03:00
fix: focus active input
This commit is contained in:
parent
616601a34a
commit
ae6244ee75
26
model.go
26
model.go
|
@ -60,12 +60,11 @@ func NewModel(defaults resend.SendEmailRequest) Model {
|
|||
from.Prompt = "From "
|
||||
from.Placeholder = "me@example.com"
|
||||
from.PromptStyle = labelStyle.Copy()
|
||||
from.PromptStyle = activeLabelStyle
|
||||
from.TextStyle = activeTextStyle
|
||||
from.PromptStyle = labelStyle
|
||||
from.TextStyle = textStyle
|
||||
from.Cursor.Style = cursorStyle
|
||||
from.PlaceholderStyle = placeholderStyle
|
||||
from.SetValue(defaults.From)
|
||||
from.Focus()
|
||||
|
||||
to := textinput.New()
|
||||
to.Prompt = "To "
|
||||
|
@ -101,6 +100,19 @@ func NewModel(defaults resend.SendEmailRequest) Model {
|
|||
body.SetValue(defaults.Text)
|
||||
body.Blur()
|
||||
|
||||
// Decide which input to focus.
|
||||
var state State
|
||||
switch {
|
||||
case defaults.From == "":
|
||||
state = editingFrom
|
||||
case len(defaults.To) == 0:
|
||||
state = editingTo
|
||||
case defaults.Subject == "":
|
||||
state = editingSubject
|
||||
case defaults.Text == "":
|
||||
state = editingBody
|
||||
}
|
||||
|
||||
attachments := list.New([]list.Item{}, attachmentDelegate{}, 0, 3)
|
||||
attachments.DisableQuitKeybindings()
|
||||
attachments.SetShowTitle(true)
|
||||
|
@ -118,8 +130,8 @@ func NewModel(defaults resend.SendEmailRequest) Model {
|
|||
loadingSpinner := spinner.New()
|
||||
loadingSpinner.Spinner = spinner.Dot
|
||||
|
||||
return Model{
|
||||
state: editingFrom,
|
||||
m := Model{
|
||||
state: state,
|
||||
From: from,
|
||||
To: to,
|
||||
Subject: subject,
|
||||
|
@ -130,6 +142,10 @@ func NewModel(defaults resend.SendEmailRequest) Model {
|
|||
keymap: DefaultKeybinds(),
|
||||
loadingSpinner: loadingSpinner,
|
||||
}
|
||||
|
||||
m.focusActiveInput()
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (m Model) Init() tea.Cmd {
|
||||
|
|
Loading…
Reference in a new issue