Tab or down from a form's Apply goes round to the first field instead of crashing the console
CI / test (push) Successful in 4m14s
CI / test (push) Successful in 4m14s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
3b22ccce72
commit
c2be429554
2 files changed
+24
-1
No files matched your search
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user