vscode: Revealing a view causes VS Code to steal focus
Does this issue occur when all extensions are disabled?: No
- VS Code Version: 1.86.2
- OS Version: Pop!_OS 22.04 LTS
Version: 1.86.2 Commit: 903b1e9d8990623e3d7da1df3d33db3e42d80eda Date: 2024-02-13T19:41:37.860Z Electron: 27.2.3 ElectronBuildId: 26908389 Chromium: 118.0.5993.159 Node.js: 18.17.1 V8: 11.8.172.18-electron.0 OS: Linux x64 6.6.10-76060610-generic
Steps to Reproduce:
- Open project with tests to run
- Change to another window
Expected: The tests should run in the background without any focus changes.
Actual: The VS Code window running the tests constantly steals window focus making doing anything whilst the tests run impossible.
It seems like every time output is written to the “TEST RESULTS” console output the host VS Code steals focus.
Stopping all Jest runners, or disabling the “Orta.vscode-jest” extension does stop the problem, however, I’m not sure if the output of that extension is just using an out of the box VS code feature, and under no circumstances should a hosted extension be allowed to be so badly behaved causing VS to steal focus repeatedly in such a disruptive manner.
About this issue
- Original URL
- State: closed
- Created 4 months ago
- Reactions: 5
- Comments: 15 (10 by maintainers)
Commits related to this issue
- Revealing a view causes VS Code to steal focus (fix #205766) — committed to microsoft/vscode by bpasero 4 months ago
- Revealing a view causes VS Code to steal focus (fix #205766) (#206712) — committed to microsoft/vscode by bpasero 4 months ago
Followup: this is kind of intended behavior because the Jest extension does not
preserveFocuswhen calling that command, so it requests that focus moves into the Test Results view. That is an issue for the Jest extension.The window focus behavior was added with the advent of floating windows so that the view is actually focused correctly, but we’ll look at making a change so that the window where the view is shown only gets focused if that group of windows is already focused.
@connectdotz that command goes here https://github.com/microsoft/vscode/blob/ff23987823aaca66f5f0064b1200a568e59ba540/src/vs/workbench/services/views/browser/viewsService.ts#L548 and you can pass
{ preserveFocus: true }as the first argument to the commandAh. I’m not sure why that would be, doesn’t seem to happen on macos but I’ll look more tomorrow 🤔
@connor4312 thanks for the tip.
IMHO this is still a bug and should be re-opened as it doesn’t do what it says on the tin; stealing window focus is not the same as opening a view. It’s an accessibility and usability nightmare (especially when it’s not clear why it’s happening or how to stop it). This behaviour makes the feature unusable.
If some people want focus to be stolen, I think that should be a clear and separate opt-in option (perhaps with less intrusive options such as a sound or system notification).
This is configurable via the
testing.openTestingsettingMy front-end uses vite, not jest and exhibits the same bad behavior, plus the problem was introduced very recently after an upgrade to VS Code (I believe code_1.86.1-1707298119_amd64.deb)