Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Jul 2, 2025

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: Added preserveFocus: true option to vscode.window.showTextDocument() calls in the openDiffEditor() method (lines 507 and 537)
  • This prevents VSCode from stealing focus from the chat input when files are opened during automated editing

Testing

  • src/integrations/editor/__tests__/DiffViewProvider.spec.ts: Added comprehensive unit tests for focus preservation behavior
  • apps/vscode-e2e/src/suite/tools/focus-preservation.test.ts: Added E2E integration tests to verify focus remains in chat during automated workflows

Testing

Manual Testing

  • ✅ Verified focus remains in chatbox during automated file creation
  • ✅ Tested continuous typing while Roo edits multiple files
  • ✅ Confirmed paste operations stay in chat input, not files
  • ✅ Tested with different file types and rapid file operations

Automated Testing

  • ✅ Unit tests pass for DiffViewProvider focus behavior
  • ✅ E2E tests verify end-to-end focus preservation workflow
  • ✅ Regression tests confirm existing diff view functionality intact

Verification

Reproduction Steps Verified

  1. ✅ Tell Roo to create 4 short hello world scripts
  2. ✅ Start typing in chat box while workflow continues
  3. Result: Focus stays in chat box, no longer switches to files

Edge Cases Tested

  • ✅ Multiple rapid file operations
  • ✅ Large file editing workflows
  • ✅ Both sidebar and tab panel modes
  • ✅ Manual file editing workflows remain unchanged

Impact

  • Security: Prevents accidental insertion of sensitive data into files
  • UX: Users can now type continuously in chat during automation
  • Compatibility: Zero breaking changes - only adds optional parameter
  • Risk: Minimal - leverages existing VSCode API patterns used elsewhere in codebase

Fixes #4574


Important

Added preserveFocus: true to prevent chatbox focus loss during automated file editing in VSCode.

  • Behavior:
    • Added preserveFocus: true to vscode.window.showTextDocument() in DiffViewProvider.ts to prevent focus loss from chatbox during automated file editing.
    • Ensures focus remains in chat input when files are opened during automation.
  • Testing:
    • Added unit tests in DiffViewProvider.spec.ts for focus preservation.
    • Added E2E tests in focus-preservation.test.ts to verify chat focus during automated workflows.
  • Misc:
    • Removed unnecessary await in scrollToFirstDiff() in applyDiffTool.ts and multiApplyDiffTool.ts.

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

Copilot AI review requested due to automatic review settings July 2, 2025 17:53
@hannesrudolph hannesrudolph requested review from cte, jr and mrubens as code owners July 2, 2025 17:53
@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Jul 2, 2025
@dosubot dosubot bot added bug Something isn't working UI/UX UI/UX related or focused labels Jul 2, 2025

This comment was marked as outdated.

@delve-auditor
Copy link

delve-auditor bot commented Jul 2, 2025

No security or compliance issues detected. Reviewed everything up to 34492c8.

Security Overview
  • 🔎 Scanned files: 4 changed file(s)
Detected Code Changes

The diff is too large to display a summary of code changes.

Reply to this PR with @delve-auditor followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

- 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
@hannesrudolph hannesrudolph force-pushed the fix/issue-4574-focus-preservation branch from 6f57ac4 to 4dcdc18 Compare July 2, 2025 17:58
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Jul 2, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 2, 2025
- 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
@hannesrudolph hannesrudolph requested a review from Copilot July 2, 2025 18:33
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 2, 2025
Copy link
Contributor

Copilot AI left a 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: true to all showTextDocument calls in DiffViewProvider
  • Made scrollToFirstDiff asynchronous and introduced restoreEditorFocus to re-focus the chat/editor after diffs
  • Updated core tools and tests to await the 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

@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jul 2, 2025
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jul 4, 2025
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 4, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 4, 2025
@mrubens mrubens merged commit ede228e into main Jul 4, 2025
13 checks passed
@mrubens mrubens deleted the fix/issue-4574-focus-preservation branch July 4, 2025 00:43
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Jul 4, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 4, 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 lgtm This PR has been approved by a maintainer PR - Needs Preliminary Review size:S This PR changes 10-29 lines, ignoring generated files. UI/UX UI/UX related or focused

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

chatbox loses focus during automated workflow

4 participants