Skip to content

macOS: New setting for always opening new windows in native tabs #250042

@lionel-

Description

@lionel-

Currently a user can set window.nativeTabs but to be able to create such tabs there's only these options:

  • Set "Prefer tabs" to "Always" in the global macOS settings. This works because if window.nativeTabs is set to true, VS Code sets tabbingIdentifier, which causes macOS to open in a native tab when the global option is set.

  • Call the workbench.action.newWindowTab command, also accessible by menu with Window -> New Tab (see Add a command to open a new window as tab (Sierra tabs) #25919). This causes VS Code to call addTabbedWindow to force opening in a tab regardless of the global macOS setting.

Both of these have drawbacks:

  • Setting the global option is not desirable for all users as this has global effect, for instance this causes Finder windows to always open in tabs.

  • Using the newWindowTab command does not work in the general case, for instance when using other commands or actions that open a new window.

Furthermore the current behavior is non-obvious as users expect enabling native tabs would immediately work for all actions that create a new window. It's not obvious users need to change the global setting, see #25919 (comment), and I saw other comments from confused users in other posts.

I think ideally setting window.nativeTabs to true should cause all new windows to open in tabs by default. Creating a new window would still be possible by first creating a new tab then dragging it out, same process as when the global macOS setting for tabs is set to "always". However I guess it's too late to change that behaviour so the next best thing would be to add a new setting.

The following patch works well for me. It calls addTabbedWindow() for all new windows if the window.openNewWindowsInNativeTabs is set:

diff --git a/src/vs/platform/windows/electron-main/windowsMainService.ts b/src/vs/platform/windows/electron-main/windowsMainService.ts
index 594b8364353..04547d828f1 100644
--- a/src/vs/platform/windows/electron-main/windowsMainService.ts
+++ b/src/vs/platform/windows/electron-main/windowsMainService.ts
@@ -1529,9 +1529,10 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
 			});
 			mark('code/didCreateCodeWindow');

 			// Add as window tab if configured (macOS only)
-			if (options.forceNewTabbedWindow) {
+			const forceNewTabbedWindow = this.configurationService.getValue<boolean>('window.openNewWindowsInNativeTabs')
+			if (forceNewTabbedWindow || options.forceNewTabbedWindow) {
 				const activeWindow = this.getLastActiveWindow();
 				activeWindow?.addTabbedWindow(createdWindow);
 			}

I'd be happy to send a PR with a properly documented setting if you're interested.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions