Fix Settings page key navigation order#77
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request introduces a settingsFocusOrder slice to explicitly define the keyboard navigation order in the settings page, decoupling it from the enum order. It also updates the cycleFocus method to utilize this new order and adds a corresponding test case. Feedback suggests adding a defensive test to ensure the focus order remains synchronized with the field enum and improving the robustness of the index lookup in cycleFocus to handle cases where the focused field might not be found in the slice.
| fieldCount // sentinel | ||
| ) | ||
|
|
||
| var settingsFocusOrder = []settingsField{ |
There was a problem hiding this comment.
The settingsFocusOrder slice must be manually kept in sync with the settingsField enum and the layout in renderContent. If a new field is added to the enum but omitted from this slice, it will be unreachable via keyboard navigation. Consider adding a defensive check in a test to ensure len(settingsFocusOrder) == int(fieldCount) and that all fields are present.
| currentIdx := 0 | ||
| for i, field := range settingsFocusOrder { | ||
| if field == p.focused { | ||
| currentIdx = i | ||
| break | ||
| } | ||
| } |
There was a problem hiding this comment.
Initializing currentIdx to 0 makes it impossible to distinguish between the first field being focused and the focused field not being found in the settingsFocusOrder list. While p.focused is currently initialized correctly, this is fragile. Initializing to -1 and handling the "not found" case explicitly would be more robust.
currentIdx := -1
for i, field := range settingsFocusOrder {
if field == p.focused {
currentIdx = i
break
}
}
if currentIdx == -1 {
currentIdx = 0
}Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces an explicit focus order for the settings page fields by adding a settingsFocusOrder slice and updating the cycleFocus logic. This ensures that keyboard navigation follows a specific sequence regardless of the underlying enum values. Additionally, several unit tests were added to verify the navigation order, ensure all fields are covered, and test recovery from unknown focus states. I have no feedback to provide.
Summary
Testing