Skip to content

Add option to disable/enable focus on diff view #6010

@felixAnhalt

Description

@felixAnhalt

What specific problem does this solve?

When Roo opens a diff editor, it automatically steals focus (after #5672) from the user’s current editor, interrupting their workflow. Some users prefer to keep their focus on the original file or another editor, especially when reviewing changes or multitasking. This is a more expansive approach to handle the file editing experience.

Who is affected?

Users who want to control focus behavior when Roo opens diff editors.

When does this happen?

When Roo opens a diff editor as part of its operations.

Current vs. expected behaviour:

Currently, the diff editor may always gain focus. With this feature, users can configure whether the diff editor should auto-focus or not.

Impact:

Provides a smoother, less disruptive workflow for users who want to control editor focus.

Additional context (optional)

There is already a reference implementation inside #2955
The refence implementation was also already extracted into its own branch.
This issue is part of a series of proposed features which came to be by the discussions in said pull request.
This issue makes sense after #5672

The proposed complete feature set being:

  • Adding file based editing with the (least amount of control visually)
  • Adding option to enable/disable autofocus to follow the visual editing process (most control visually)
  • Adding option to open tabs in correct tab group if autofocus disabled
  • Adding option to open tabs at the end of the tab list in the current tab group
  • Adding settings to control tab closing behavior (opening tabs after edits, closing tabs after edits, closing all tabs of files touched

These should reside inside the FileEditingOptions proposed in Technical considerations
For a look at the complete feature set have a look into #2955

Roo Code Task Links (Optional)

No response

Request checklist

  • I've searched existing Issues and Discussions for duplicates
  • This describes a specific problem with clear impact and context

Interested in implementing this?

  • Yes, I'd like to help implement this feature

Implementation requirements

  • I understand this needs approval before implementation begins

How should this be solved? (REQUIRED if contributing, optional otherwise)

Add a user setting diffViewAutoFocus (default: false).
When enabled, Roo diff editors will automatically gain focus when opened.
When disabled, Roo diff editors will open in the background, preserving the user’s current focus.
This is implemented by passing the correct preserveFocus option to VSCode’s APIs and related methods and using the correct ViewColumn based on the ClineProvider.

How will we know it works? (Acceptance Criteria - REQUIRED if contributing, optional otherwise)

Given I am working in a file and trigger a Roo diff with diffViewAutoFocus enabled
When the diff editor opens
Then the diff editor gains focus
And my cursor is placed at the start of the diff
But no other editors are focused

Given I am working in a file and trigger a Roo diff with diffViewAutoFocus disabled
When the diff editor opens
Then my current editor remains focused
And the diff editor opens in the background
But my workflow is not interrupted by a focus change

Technical considerations (REQUIRED if contributing, optional otherwise)

Add the diffViewAutoFocus setting to the Roo configuration.
When opening a diff editor, read this setting and pass the appropriate preserveFocus value to VSCode’s API.
Use ClineProvider to determine the correct editor group (ViewColumn) for tab placement, ensuring the diff opens in the intended group.
If diffViewAutoFocus is enabled, the diff editor gains focus; if disabled, the current editor remains focused and the diff opens in the background.
Ensure the implementation works for both single and multi-group layouts, and that state is synchronized via the ClineProvider’s view property.
Add automated tests to verify correct focus and placement behavior for all combinations of settings and workspace layouts.

Add new FileEditingOptions options section inside webview-ui/src/components/settings/SettingsView.tsx.
Add the setting for diffViewAutoFocus inside src/core/webview/webviewMessageHandler.ts etc.

Affected: DiffViewProvider and webview-ui/src/components/settings/SettingsView.tsx and ClineProvider

Trade-offs and risks (REQUIRED if contributing, optional otherwise)

If VSCode changes its focus/tab APIs, adjustments may be needed.
Edge cases may arise with rapid tab opening or user-initiated focus changes, but the logic is modular and easily extendable.

Potential negative impacts (performance, UX, etc.)

preserveFocus is being ignored when providing a ViewColumn other than ViewColumn.Beside.
Therefore, showTextDocument is needed for the tab and selection active prior to vscode.diff invocation.
The vscode.diff invocation steals focus for a short period of time.

Metadata

Metadata

Assignees

Labels

Issue - In ProgressSomeone is actively working on this. Should link to a PR soon.enhancementNew feature or requestfeature requestFeature request, not a bugproposal

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions