Skip to content

Commit dd3f797

Browse files
committed
pam/newpasswordmodel: Do not ignore the potential Focus command on clear
During Clear we were focusing again the focus widget, however the Focus call may return a command that should still be delivered and not ignored So do it.
1 parent 4c86ccb commit dd3f797

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

pam/internal/adapter/newpasswordmodel.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,11 @@ func (m newPasswordModel) Init() tea.Cmd {
6565
func (m newPasswordModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6666
switch msg := msg.(type) {
6767
case startAuthentication:
68-
m.Clear()
69-
return m, m.updateFocusModel(msg)
68+
return m, tea.Sequence(m.Clear(), m.updateFocusModel(msg))
7069

7170
case newPasswordCheckResult:
7271
if msg.msg != "" {
73-
m.Clear()
74-
return m, sendEvent(errMsgToDisplay{msg: msg.msg})
72+
return m, tea.Sequence(m.Clear(), sendEvent(errMsgToDisplay{msg: msg.msg}))
7573
}
7674

7775
return m, tea.Batch(sendEvent(errMsgToDisplay{}), m.focusNextField())
@@ -122,8 +120,8 @@ func (m newPasswordModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
122120
if m.focusIndex == 1 {
123121
// Check both entries are matching
124122
if m.passwordEntries[0].Value() != m.passwordEntries[1].Value() {
125-
m.Clear()
126-
return m, sendEvent(errMsgToDisplay{msg: "Password entries don't match"})
123+
return m, tea.Sequence(m.Clear(),
124+
sendEvent(errMsgToDisplay{msg: "Password entries don't match"}))
127125
}
128126
}
129127

@@ -233,8 +231,9 @@ func (m *newPasswordModel) focusPrevField() tea.Cmd {
233231
return m.focusField(-1)
234232
}
235233

236-
func (m *newPasswordModel) Clear() {
234+
func (m *newPasswordModel) Clear() tea.Cmd {
237235
m.focusIndex = 0
236+
var cmd tea.Cmd
238237
for i, fm := range m.focusableModels {
239238
switch entry := fm.(type) {
240239
case *textinputModel:
@@ -244,6 +243,7 @@ func (m *newPasswordModel) Clear() {
244243
fm.Blur()
245244
continue
246245
}
247-
fm.Focus()
246+
cmd = fm.Focus()
248247
}
248+
return cmd
249249
}

0 commit comments

Comments
 (0)