-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: prevent chatbox focus loss during automated file editing (#4574) #5349
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
|
✅ No security or compliance issues detected. Reviewed everything up to 34492c8. Security Overview
Detected Code ChangesThe diff is too large to display a summary of code changes. Reply to this PR with |
- Add preserveFocus: true to DiffViewProvider openDiffEditor method - Implement comprehensive focus preservation during cursor positioning and scrolling - Make scrollToFirstDiff async with focus restoration capabilities - Update all tool files to use async scrollToFirstDiff - Add comprehensive unit and E2E tests for focus preservation Fixes #4574
6f57ac4 to
4dcdc18
Compare
- Created restoreEditorFocus() helper method to eliminate code duplication - Changed preserveFocus from false to true for consistent behavior - Added error handling with silent logging for focus restoration failures - Added null checks for undefined activeTextEditor cases
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.
Pull Request Overview
This PR ensures the chatbox retains focus during automated file editing by leveraging VSCode’s preserveFocus option and restoring focus after scrolling.
- Added
preserveFocus: trueto allshowTextDocumentcalls inDiffViewProvider - Made
scrollToFirstDiffasynchronous and introducedrestoreEditorFocusto re-focus the chat/editor after diffs - Updated core tools and tests to
awaitthe new async scrolling behavior and verify focus preservation
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/integrations/editor/DiffViewProvider.ts | Added preserveFocus flags and implemented focus restoration in diff view methods |
| src/integrations/editor/tests/DiffViewProvider.spec.ts | Updated tests to expect preserveFocus: true in showTextDocument calls |
| src/core/tools/writeToFileTool.ts | Changed scrollToFirstDiff() calls to await the new async method |
| src/core/tools/searchAndReplaceTool.ts | Same update: await scrollToFirstDiff() |
| src/core/tools/insertContentTool.ts | Same update: await scrollToFirstDiff() |
| apps/vscode-e2e/src/suite/tools/focus-preservation.test.ts | New E2E tests for focus preservation during multiple/rapid file operations |
It doesn't seem to be testing anything
Description
Fixes a critical UX issue where the chatbox loses focus during automated workflows, causing user input to be redirected to files being edited by Roo. This prevented users from typing in chat during automation and led to dangerous scenarios where sensitive data (like API keys) could accidentally be pasted into random files.
Changes Made
Core Fix
src/integrations/editor/DiffViewProvider.ts: AddedpreserveFocus: trueoption tovscode.window.showTextDocument()calls in theopenDiffEditor()method (lines 507 and 537)Testing
src/integrations/editor/__tests__/DiffViewProvider.spec.ts: Added comprehensive unit tests for focus preservation behaviorapps/vscode-e2e/src/suite/tools/focus-preservation.test.ts: Added E2E integration tests to verify focus remains in chat during automated workflowsTesting
Manual Testing
Automated Testing
DiffViewProviderfocus behaviorVerification
Reproduction Steps Verified
Edge Cases Tested
Impact
Fixes #4574
Important
Added
preserveFocus: trueto prevent chatbox focus loss during automated file editing in VSCode.preserveFocus: truetovscode.window.showTextDocument()inDiffViewProvider.tsto prevent focus loss from chatbox during automated file editing.DiffViewProvider.spec.tsfor focus preservation.focus-preservation.test.tsto verify chat focus during automated workflows.awaitinscrollToFirstDiff()inapplyDiffTool.tsandmultiApplyDiffTool.ts.This description was created by
for 34492c8. You can customize this summary. It will automatically update as commits are pushed.