-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix chatbox losing focus during automated workflows #4577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add preserveFocus option to openFile() function to prevent focus theft - Implement automated workflow detection based on task streaming state and auto-approval settings - Preserve chat focus when AI is actively processing to prevent accidental text insertion - Update file mention handling to respect automated workflow state - Add comments to clarify user-initiated vs automated file opening 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Updated test expectation to match new preserveFocus parameter - Added ClineProvider mock for automated workflow detection - All mentions tests now pass 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
hannesrudolph
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR! This is a well-targeted fix that addresses both a UX issue and a potential security risk where users could accidentally paste sensitive information into files during automated workflows.
What I liked:
- ✅ The solution correctly identifies automated workflows using multiple indicators
- ✅ Maintains backward compatibility for user-initiated file opening
- ✅ Includes test coverage for the new functionality
- ✅ Clear separation between automated and user-initiated actions
Suggestions:
I've left a few comments inline, mainly around:
- Extracting the duplicated workflow detection logic into a shared utility
- Adding test coverage for the automated workflow detection scenarios
- Adding explanatory comments similar to the ones you have for user-initiated actions
Overall, this is a solid implementation that solves the reported issue effectively. The code is clean and the approach makes sense. Nice work!
- Extract duplicated automated workflow detection into shared utility - Add 23 comprehensive unit tests covering all edge cases and scenarios - Add detailed JSDoc documentation with examples and issue references - Improve code maintainability and eliminate duplication Addresses PR review feedback for issue #4574. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
|
I tested this implementation but I still lost focus when Roo Code was editing files: 2025-06-12_18-11-02.mp4Am I doing something wrong? |
- Add detailed comments explaining why we preserve focus during automated workflows - Clarify the security implications of accidental API key exposure - Reference issue #4574 for additional context - Improve code documentation for future maintainers 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Add preserveFocus parameter to revealRange calls in DiffViewProvider - Use workflow detection to determine when to preserve focus during scrolling - Prevents chat from losing focus when AI is editing files with diff view - Addresses daniel-lxs's reported issue where focus was still being lost This fix ensures that when the AI is actively processing (streaming, waiting for chunks, or in auto-approval mode), the diff view won't steal focus from the chat input, preventing accidental typing in the wrong window. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
|
@daniel-lxs Can you see if this still draws away your focus? Repro steps dont seem to be consistent |
|
@hannesrudolph 2025-06-17_11-13-48.mp4 |
|
ok closing this. attempt with claude code did not work. |
|
If someone wishes to revisit this later, you might need to investigate the following:
The implementation in this PR looks solid, but if users are still experiencing focus loss, these areas would be good starting points for further investigation. |
Totally coded and submitted by Claude Code and is a test.
Related GitHub Issue
Closes: #4574
Description
This PR fixes the issue where the chatbox unexpectedly loses focus during automated file editing workflows, which was causing:
Key implementation details:
openFile()function: AddedpreserveFocusoption to prevent focus theft during automated workflowsTechnical approach:
The solution detects when the AI is actively working (streaming, waiting for chunks, auto-approval enabled with incomplete tasks) and sets
preserveFocus: trueonvscode.window.showTextDocument()calls during these periods.Test Procedure
Manual testing performed:
Verified automated workflow detection logic with comprehensive test scenarios covering:
Code quality checks:
npm run lint)preserveFocus: true(confirmed no additional changes needed)How reviewers can test:
Type of Change
<!-- Mark all applicable boxes with an 'x'. -->
srcor test files.Pre-Submission Checklist
<!-- Go through this checklist before marking your PR as ready for review. -->
npm run lint).console.log) has been removed.npm test).mainbranch.npm run changesetif this PR includes user-facing changes or dependency updates.Screenshots / Videos
<!--
For UI changes, please provide before-and-after screenshots or a short video of the actual results.
This greatly helps in understanding the visual impact of your changes.
-->
This is a focus management fix that prevents unwanted behavior rather than adding visible UI changes. The improvement is that the chatbox will now correctly maintain focus during automated workflows, preventing accidental text insertion into edited files.
Documentation Updates
<!--
Does this PR necessitate updates to user-facing documentation?
No documentation updates are required.
Yes, documentation updates are required. (Please describe what needs to be updated or link to a PR in the docs repository).
-->
No documentation updates are required.
This is an internal bug fix that improves existing functionality without changing user-facing behavior or adding new features.
Additional Notes
Security considerations:
This fix addresses a potential security risk where users could accidentally paste sensitive information (API keys, passwords) into files being edited during automated workflows.
Files changed:
src/integrations/misc/open-file.ts: AddedpreserveFocusoptionsrc/core/webview/webviewMessageHandler.ts: Enhanced automated workflow detection for file openingsrc/core/mentions/index.ts: Applied same logic to file mention handlingExisting safeguards confirmed:
preserveFocus: truefor all operationsGet in Touch
<!--
Please provide your Discord username for reviewers or maintainers to reach you if they have questions about your PR
-->
Feel free to reach out if you have any questions about the implementation or need clarification on the automated workflow detection logic.
Important
Fixes chatbox focus loss during automated workflows by enhancing
openFile()with apreserveFocusoption and implementing workflow detection.preserveFocusoption toopenFile().isInAutomatedWorkflowFromProvider()andisInAutomatedWorkflowFromVisibleProvider().webviewMessageHandler.ts,index.ts, andDiffViewProvider.ts.isInAutomatedWorkflow(),isInAutomatedWorkflowFromProvider(), andisInAutomatedWorkflowFromVisibleProvider()inworkflow-detection.ts.workflow-detection.test.ts.openFile()inopen-file.tsto supportpreserveFocusoption.This description was created by
for 52d469a. You can customize this summary. It will automatically update as commits are pushed.