Skip to content

fix(tui): preserve typed character when auto-focusing input#698

Open
cbagwell wants to merge 2 commits intoOpenHands:mainfrom
cbagwell:fix/preserve-typed-char-on-autofocus
Open

fix(tui): preserve typed character when auto-focusing input#698
cbagwell wants to merge 2 commits intoOpenHands:mainfrom
cbagwell:fix/preserve-typed-char-on-autofocus

Conversation

@cbagwell
Copy link
Copy Markdown
Contributor

When user types a printable character while focus is elsewhere than prompt input box, the auto-focus logic now captures and inserts the character into the prompt input field, instead of losing it.

When user types a printable character while focus is elsewhere
than prompt input box, the auto-focus logic now captures and inserts
the character into the prompt input field, instead of losing it.
Copy link
Copy Markdown
Collaborator

@all-hands-bot all-hands-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Acceptable - Solves a real UX problem with simple logic, but missing tests and evidence.

This fix correctly preserves typed characters during auto-focus. However, it needs test coverage to prevent future regressions.

# Store the character before changing focus so it can be inserted
char = event.character
self.input_field.focus_input()
if char:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Suggestion: The if char: check is redundant. Since event.is_printable is already True (line 560), event.character is guaranteed to have a value.

Suggested change
if char:
self.input_field.active_input_widget.insert(char)

Copy link
Copy Markdown
Contributor Author

@cbagwell cbagwell Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if char: guard was added because of pyright and is required for type safety since event.character can technically be None per the Textual type stubs, even when event.is_printable is True.

Comment thread openhands_cli/tui/textual_app.py
Co-authored-by: openhands <openhands@all-hands.dev>
@cbagwell cbagwell force-pushed the fix/preserve-typed-char-on-autofocus branch from 25962b5 to 20e65eb Compare April 26, 2026 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants