mirror of
https://github.com/ivabus/pop
synced 2025-06-08 08:00:27 +03:00
fix: focus active input
This commit is contained in:
parent
616601a34a
commit
ae6244ee75
1 changed files with 21 additions and 5 deletions
26
model.go
26
model.go
|
@ -60,12 +60,11 @@ func NewModel(defaults resend.SendEmailRequest) Model {
|
||||||
from.Prompt = "From "
|
from.Prompt = "From "
|
||||||
from.Placeholder = "me@example.com"
|
from.Placeholder = "me@example.com"
|
||||||
from.PromptStyle = labelStyle.Copy()
|
from.PromptStyle = labelStyle.Copy()
|
||||||
from.PromptStyle = activeLabelStyle
|
from.PromptStyle = labelStyle
|
||||||
from.TextStyle = activeTextStyle
|
from.TextStyle = textStyle
|
||||||
from.Cursor.Style = cursorStyle
|
from.Cursor.Style = cursorStyle
|
||||||
from.PlaceholderStyle = placeholderStyle
|
from.PlaceholderStyle = placeholderStyle
|
||||||
from.SetValue(defaults.From)
|
from.SetValue(defaults.From)
|
||||||
from.Focus()
|
|
||||||
|
|
||||||
to := textinput.New()
|
to := textinput.New()
|
||||||
to.Prompt = "To "
|
to.Prompt = "To "
|
||||||
|
@ -101,6 +100,19 @@ func NewModel(defaults resend.SendEmailRequest) Model {
|
||||||
body.SetValue(defaults.Text)
|
body.SetValue(defaults.Text)
|
||||||
body.Blur()
|
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 := list.New([]list.Item{}, attachmentDelegate{}, 0, 3)
|
||||||
attachments.DisableQuitKeybindings()
|
attachments.DisableQuitKeybindings()
|
||||||
attachments.SetShowTitle(true)
|
attachments.SetShowTitle(true)
|
||||||
|
@ -118,8 +130,8 @@ func NewModel(defaults resend.SendEmailRequest) Model {
|
||||||
loadingSpinner := spinner.New()
|
loadingSpinner := spinner.New()
|
||||||
loadingSpinner.Spinner = spinner.Dot
|
loadingSpinner.Spinner = spinner.Dot
|
||||||
|
|
||||||
return Model{
|
m := Model{
|
||||||
state: editingFrom,
|
state: state,
|
||||||
From: from,
|
From: from,
|
||||||
To: to,
|
To: to,
|
||||||
Subject: subject,
|
Subject: subject,
|
||||||
|
@ -130,6 +142,10 @@ func NewModel(defaults resend.SendEmailRequest) Model {
|
||||||
keymap: DefaultKeybinds(),
|
keymap: DefaultKeybinds(),
|
||||||
loadingSpinner: loadingSpinner,
|
loadingSpinner: loadingSpinner,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.focusActiveInput()
|
||||||
|
|
||||||
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Model) Init() tea.Cmd {
|
func (m Model) Init() tea.Cmd {
|
||||||
|
|
Loading…
Reference in a new issue