diff --git a/internal/cli/tui_actions.go b/internal/cli/tui_actions.go index a4743c88..f6b9491f 100644 --- a/internal/cli/tui_actions.go +++ b/internal/cli/tui_actions.go @@ -122,7 +122,10 @@ func (m consoleModel) actionKey(k tea.KeyMsg) (tea.Model, tea.Cmd, bool) { case tea.KeyEsc: m.formD = nil case tea.KeyTab, tea.KeyDown: - f.fields[f.focus].text.Blur() + // From Apply, which is past the last field, round to the first. + if f.focus < len(f.fields) { + f.fields[f.focus].text.Blur() + } f.focus = (f.focus + 1) % (len(f.fields) + 1) if f.focus < len(f.fields) { f.fields[f.focus].text.Focus() diff --git a/internal/cli/tui_actions_test.go b/internal/cli/tui_actions_test.go index 00914548..9383313a 100644 --- a/internal/cli/tui_actions_test.go +++ b/internal/cli/tui_actions_test.go @@ -429,3 +429,23 @@ func TestNextFindsTheNextMatchAndComesRound(t *testing.T) { t.Errorf("hits %v, went %v", hits, seen) } } + +func TestTabAndArrowsGoRoundAFormFromApplyWithoutFalling(t *testing.T) { + m, _ := consoleWith(t, cQuotas) + var tm tea.Model = press(m, "a") + n := len(tm.(consoleModel).formD.fields) + // Round the form twice each way, through Apply. + for range 2 * (n + 1) { + tm = press(tm, "tab") + } + for range 2 * (n + 1) { + tm, _ = tm.Update(tea.KeyMsg{Type: tea.KeyUp}) + tm, _ = tm.Update(tea.KeyMsg{Type: tea.KeyShiftTab}) + } + for range 2 * (n + 1) { + tm = press(tm, "down") + } + if f := tm.(consoleModel).formD; f == nil || f.focus < 0 || f.focus > n { + t.Fatalf("focus %+v", f) + } +}