open-code-review icon indicating copy to clipboard operation
open-code-review copied to clipboard

fix(cli): refocus previous input on esc in manual provider form

Open hanhaiqingchuan opened this issue 4 months ago • 2 comments

Description

In ocr config provider, the Manual tab form loses input focus when the user presses Esc to go back to a previous field. For example: fill in the URL, press Enter to reach the Protocol step, then press Esc to go back and edit the URL — the URL field is rendered as active, but it has no cursor and ignores all typing. The same back-navigation works correctly in the Custom provider form.

Root cause: focusManualStep is declared with a value receiver, while textinput.Model.Focus() uses a pointer receiver. In the Esc branch of updateManualForm (return m, m.focusManualStep()), the method receives a copy of the model, so Focus() marks the input as focused only on that discarded copy — the model actually returned from Update still holds a blurred input, and bubbles' textinput ignores key messages while blurred.

The fix changes focusManualStep to a pointer receiver, matching its Custom-form counterpart focusCPStep (which is why the Custom form was unaffected). All back-navigation paths with a text input are covered: Protocol→URL, Auth Token→Model, Auth Header→Auth Token. (Model→Protocol was unaffected: the protocol step has no text input.)

Type of Change

  • [X] Bug fix (non-breaking change that fixes an issue)

How Has This Been Tested?

  • [X] make test passes locally

  • [X] Manual testing (describe below)

  • Added TestProviderTUI_ManualFormEscRefocusesPreviousInput, a table-driven regression test covering the three back-navigation paths that land on a text input. Each case asserts the previous step's input is focused after Esc and accepts subsequent typing. Verified the test fails on the unfixed code (all three cases) and passes with the fix.

  • Full suite: make check and make test (with -race) pass locally.

  • Manual testing with a locally built binary (ocr config provider, isolated $HOME sandbox): Manual tab → fill URL → Enter → Esc — the URL field regains the cursor and is editable again; same verified for the Auth Token and Auth Header back-navigation paths. Reproduced the broken behavior with an unfixed main binary as an A/B control.

Checklist

  • [X] My code follows the project's coding style (go fmt, go vet)
  • [X] I have performed a self-review of my code
  • [X] I have added tests that prove my fix is effective or my feature works
  • [X] New and existing unit tests pass locally with my changes
  • [ ] I have updated the documentation accordingly (if applicable) — not applicable, no user-facing docs describe this interaction
  • [X] I have signed the CLA

Related Issues

Closes #628

hanhaiqingchuan avatar Jul 31 '26 07:07 hanhaiqingchuan

✅ OpenCodeReview: No comments generated. Looks good to me.

github-actions[bot] avatar Jul 31 '26 07:07 github-actions[bot]

Thanks for the PR! I've gone through the changes and they look good to me.

5wxwxwxw5 avatar Jul 31 '26 08:07 5wxwxwxw5