Skip to content

fix(vscode-ide-companion): preserve terminal focus when closing diff tabs#28183

Open
gaurav0107 wants to merge 1 commit into
google-gemini:mainfrom
gaurav0107:fix/22193-vscode-diff-preserve-focus
Open

fix(vscode-ide-companion): preserve terminal focus when closing diff tabs#28183
gaurav0107 wants to merge 1 commit into
google-gemini:mainfrom
gaurav0107:fix/22193-vscode-diff-preserve-focus

Conversation

@gaurav0107

Copy link
Copy Markdown
Contributor

Summary

When using the VS Code companion extension, approving a file edit in the
Gemini CLI closes the background diff preview and steals keyboard focus from
the integrated terminal. The user then has to click back into the terminal
before every subsequent edit. This change keeps focus in the terminal by
passing VS Code's preserveFocus flag when the diff tab is closed.

Details

The companion opens the diff preview as a background tab (vscode.diff with
preserveFocus: true) while the user works in the terminal where the Gemini
CLI runs. On closeDiff, DiffManager.closeDiffEditor in
packages/vscode-ide-companion/src/diff-manager.ts closes that tab with
vscode.window.tabGroups.close(tab). VS Code's default behavior when a tab is
closed is to move focus into the editor area. Passing the second positional
argument to TabGroups.close(tabs, preserveFocus?) as true keeps focus in
its current position (the terminal):

await vscode.window.tabGroups.close(tab, true);

This is a one-line behavioral fix plus a focused regression test.

It resurrects the one-line fix that was reviewed and approved by @kschaab
in #23215, which was auto-closed by the 30-day inactivity bot rather than on
merits (the alternative #22331 is closed). #23215 shipped without a test; this
PR adds the missing regression coverage in src/diff-manager.test.ts,
asserting tabGroups.close is invoked with preserveFocus = true when a diff
tab is closed (the test fails on the old close(tab) call and passes with the
fix).

Related Issues

Fixes #22193

How to Validate

Automated:

  • npm test -w packages/vscode-ide-companion — the new src/diff-manager.test.ts
    passes and the full package suite is green (41 passed, 1 skipped).
  • npm run lint -w packages/vscode-ide-companion and tsc --noEmit pass.

Manual (validation steps from #23215):

  1. Build the companion extension: npm run build -w packages/vscode-ide-companion
  2. Start the Gemini CLI in VS Code's integrated terminal.
  3. Prompt Gemini to make a code edit that requires user approval.
  4. When prompted with [Proceed] in the terminal, press Enter.
  5. Focus should remain in the terminal, and the next Enter keypress should act
    on the CLI instead of inserting a newline in an editor tab.

Pre-Merge Checklist

Note: I am a first-time contributor to this organization and still need to
sign the Google CLA at https://cla.developers.google.com/ when googlebot
comments. The automated checks above pass; manual GUI focus validation is
pending a local VS Code session.

@github-actions github-actions Bot added the size/m A medium sized PR label Jun 28, 2026
@github-actions

github-actions Bot commented Jun 28, 2026

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 116
  • Additions: +115
  • Deletions: -1
  • Files changed: 2

@gaurav0107 gaurav0107 marked this pull request as ready for review June 28, 2026 10:09
@gaurav0107 gaurav0107 requested a review from a team as a code owner June 28, 2026 10:09
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a usability issue where closing a diff preview tab in the VS Code companion extension causes the editor to steal keyboard focus from the integrated terminal. By ensuring the preserveFocus flag is passed during tab closure, the extension now maintains the user's focus in the terminal, improving the workflow for Gemini CLI interactions.

Highlights

  • Preserve Terminal Focus: Updated the diff tab closure logic to pass the preserveFocus: true flag, preventing the editor from stealing focus from the integrated terminal when a diff is closed.
  • Regression Testing: Added a new test suite in diff-manager.test.ts to verify that vscode.window.tabGroups.close is correctly invoked with the preserveFocus parameter.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the DiffManager to pass preserveFocus=true when closing background diff tabs, ensuring that keyboard focus remains in the integrated terminal. A new test suite is added to verify this behavior. The review feedback correctly points out that vscode.window.tabGroups.all should be reset in beforeEach to prevent test pollution and ensure proper test isolation.

Comment thread packages/vscode-ide-companion/src/diff-manager.test.ts
…tabs

Closing the background diff tab via tabGroups.close(tab) lets VS Code move
keyboard focus into the editor area, stealing focus from the integrated
terminal where the Gemini CLI runs. Pass preserveFocus=true so focus stays
put, letting users step through edits without re-clicking the terminal pane.

Adds a regression test asserting tabGroups.close is invoked with
preserveFocus=true when a diff tab is closed.

Fixes google-gemini#22193
@gaurav0107 gaurav0107 force-pushed the fix/22193-vscode-diff-preserve-focus branch from c9f4074 to ff24aa9 Compare June 28, 2026 10:12
@gemini-cli gemini-cli Bot added priority/p1 Important and should be addressed in the near term. area/extensions Issues related to Gemini CLI extensions capability help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/extensions Issues related to Gemini CLI extensions capability help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p1 Important and should be addressed in the near term. size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gemini CLI doesn't maintain keyboard focus when VS Code extension closes a diff

1 participant