Skip to content

Commit b9947f2

Browse files
author
Benjamin Pasero
committed
If I switch workspace, focus moves to different VS Code instance (fix microsoft#106727)
1 parent 79e1ebb commit b9947f2

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/vs/code/electron-main/window.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
338338
}
339339

340340
focus(options?: { force: boolean }): void {
341-
// macOS: Electron >6.x changed its behaviour to not
341+
// macOS: Electron > 7.x changed its behaviour to not
342342
// bring the application to the foreground when a window
343343
// is focused programmatically. Only via `app.focus` and
344344
// the option `steal: true` can you get the previous

src/vs/platform/launch/electron-main/launchMainService.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,18 @@ export class LaunchMainService implements ILaunchMainService {
7373
async start(args: NativeParsedArgs, userEnv: IProcessEnvironment): Promise<void> {
7474
this.logService.trace('Received data from other instance: ', args, userEnv);
7575

76-
// Since we now start to open a window, make sure the app has focus.
77-
// Focussing a window will not ensure that the application itself
78-
// has focus, so we use the `steal: true` hint to force focus.
79-
app.focus({ steal: true });
76+
// macOS: Electron > 7.x changed its behaviour to not
77+
// bring the application to the foreground when a window
78+
// is focused programmatically. Only via `app.focus` and
79+
// the option `steal: true` can you get the previous
80+
// behaviour back. The only reason to use this option is
81+
// when a window is getting focused while the application
82+
// is not in the foreground and since we got instructed
83+
// to open a new window from another instance, we ensure
84+
// that the app has focus.
85+
if (isMacintosh) {
86+
app.focus({ steal: true });
87+
}
8088

8189
// Check early for open-url which is handled in URL service
8290
const urlsToOpen = parseOpenUrl(args);

0 commit comments

Comments
 (0)