Keep the application's focus in step with arrow-key moves in forms
Form.SetFocus moves between items without telling the application, which kept the item that was left. Opening the help from the Config view then blurred only that one: the field in use kept drawing its cursor through the help window, the form still had the focus and took the help's keys (no scrolling), and closing the help returned to the wrong field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019reK4DUGYqDUjniWYJvwUW
This commit is contained in:
@@ -313,3 +313,30 @@ func TestTestConnectionsButtonSitsBelowTheServices(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHelpOverConfigTakesTheFocus(t *testing.T) {
|
||||
a := newTestApp(t)
|
||||
a.handleKey(tcell.NewEventKey(tcell.KeyF6, 0, 0))
|
||||
moveDown := a.settings.form.GetInputCapture()
|
||||
moveDown(tcell.NewEventKey(tcell.KeyDown, 0, 0))
|
||||
moveDown(tcell.NewEventKey(tcell.KeyDown, 0, 0))
|
||||
field := a.settings.inputs["radarr.profile"]
|
||||
if a.app.GetFocus() != field {
|
||||
t.Fatalf("after ↓↓ the application's focus is %T, not the third field", a.app.GetFocus())
|
||||
}
|
||||
|
||||
a.handleKey(tcell.NewEventKey(tcell.KeyF9, 0, 0))
|
||||
// The field must not keep the focus behind the help: it would draw its
|
||||
// cursor through the window, and the form would take the help's keys.
|
||||
if field.HasFocus() || a.settings.form.HasFocus() {
|
||||
t.Errorf("behind the help: field focused %v, form focused %v", field.HasFocus(), a.settings.form.HasFocus())
|
||||
}
|
||||
if _, ok := a.app.GetFocus().(*tview.TextView); !ok {
|
||||
t.Errorf("help has no focus: %T", a.app.GetFocus())
|
||||
}
|
||||
|
||||
a.closeModal()
|
||||
if a.app.GetFocus() != field || !field.HasFocus() {
|
||||
t.Errorf("closing the help returns to %T, not the field that was in use", a.app.GetFocus())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user