Skip to content

Conversation

@MuriloFP
Copy link
Contributor

@MuriloFP MuriloFP commented Jul 17, 2025

PR Title: fix: restore focus to chat text box after Alt+Tab (#2189)


Related GitHub Issue

Closes: #2189

Roo Code Task Context (Optional)

N/A

Description

This PR addresses the issue where users lose focus from the Roo Code chat text box when switching away from VSCode using Alt+Tab and then switching back.

Key implementation details:

  • Added a window focus event listener in ChatView.tsx that triggers when the window regains focus
  • The listener checks if the text area should be focusable using existing conditions: !isHidden && !sendingDisabled && !enableButtons
  • Used setTimeout with 0ms delay to ensure focus happens after the event loop cycle for better reliability across different platforms
  • Added proper cleanup of the event listener on component unmount to prevent memory leaks

Design choices:

  • Reused existing focus conditions to maintain consistency with current behavior
  • The window focus event approach was chosen as it specifically targets the Alt+Tab scenario without interfering with other focus behaviors
  • The setTimeout ensures the focus action happens after VSCode's webview has fully processed the window focus event

Test Procedure

Unit tests added:

  • Added tests in ChatView.spec.tsx to verify window focus event listener setup and cleanup
  • Added test to verify focus restoration when conditions are met
  • Tests pass with npx vitest run src/components/chat/__tests__/ChatView.spec.tsx

Manual testing steps:

  1. Open VSCode with Roo Code extension
  2. Start typing in the Roo Code chat text box
  3. Press Alt+Tab to switch to another application
  4. Press Alt+Tab again to switch back to VSCode
  5. Verify that the cursor is back in the chat text box and you can continue typing immediately

Testing environment: Windows 11, VSCode 1.95.0, Roo Code v3.11.3

Additional test scenarios:

  • Verified focus is NOT restored when the chat view is hidden
  • Verified focus is NOT restored when a tool is running (sending disabled)
  • Verified focus is NOT restored when confirmation buttons are shown

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

N/A - No UI changes. This is a focus behavior fix that doesn't alter the visual appearance.

Documentation Updates

  • No documentation updates are required.

Additional Notes

This fix specifically addresses the VSCode webview focus loss issue reported by multiple users. The implementation is minimal and follows React best practices for effect handling and focus management.

Get in Touch

@MuriloFP


Important

Adds window focus event listener in ChatView.tsx to restore focus to chat text box after Alt+Tab, with tests verifying functionality.

  • Behavior:
    • Adds window focus event listener in ChatView.tsx to restore focus to chat text box after Alt+Tab.
    • Uses setTimeout to ensure focus restoration after event loop cycle.
    • Cleans up event listener on component unmount.
  • Tests:
    • Adds tests in ChatView.spec.tsx to verify window focus event listener setup and cleanup.
    • Tests focus restoration when conditions are met.
    • Tests pass with npx vitest run src/components/chat/__tests__/ChatView.spec.tsx.

This description was created by Ellipsis for e63ed48. You can customize this summary. It will automatically update as commits are pushed.

MuriloFP and others added 21 commits July 3, 2025 15:26
- Add window focus event listener to ChatView component
- Automatically restore focus when window regains focus and conditions are met
- Use setTimeout to ensure focus happens after event loop cycle
- Add comprehensive tests for focus restoration functionality
- Properly clean up event listener on component unmount

This fix addresses the issue where users lose focus from the chat text box
when switching away from VSCode using Alt+Tab and then switching back.
@MuriloFP MuriloFP requested review from cte, jr and mrubens as code owners July 17, 2025 19:09
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jul 17, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 17, 2025
@daniel-lxs
Copy link
Member

I'm unable to reproduce the issue on main, Would it be good to demonstrate the issue to check if this PR fixes it?

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jul 19, 2025
@MuriloFP
Copy link
Contributor Author

Seems the issue was fixed on main somehow... Closing this PR.

@MuriloFP MuriloFP closed this Jul 21, 2025
@github-project-automation github-project-automation bot moved this from PR [Changes Requested] to Done in Roo Code Roadmap Jul 21, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working PR - Changes Requested size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Focus Lost in Chat Text Box After Alt+Tab

3 participants