Skip to content

Commit 6bca69f

Browse files
authored
macos - restore Cmd+W to close window when no editors opened (microsoft#126045)
1 parent b9f4ab0 commit 6bca69f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/vs/workbench/electron-sandbox/actions/windowActions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis
2727

2828
export class CloseWindowAction extends Action2 {
2929

30+
static readonly ID = 'workbench.action.closeWindow';
31+
3032
constructor() {
3133
super({
32-
id: 'workbench.action.closeWindow',
34+
id: CloseWindowAction.ID,
3335
title: {
3436
value: localize('closeWindow', "Close Window"),
3537
mnemonicTitle: localize({ key: 'miCloseWindow', comment: ['&& denotes a mnemonic'] }, "Clos&&e Window"),

src/vs/workbench/electron-sandbox/desktop.contribution.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } fr
2323
import { PartsSplash } from 'vs/workbench/electron-sandbox/splash';
2424
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
2525
import { InstallShellScriptAction, UninstallShellScriptAction } from 'vs/workbench/electron-sandbox/actions/installActions';
26+
import { EditorsVisibleContext, SingleEditorGroupsContext } from 'vs/workbench/common/editor';
2627

2728
// Actions
2829
(function registerActions(): void {
@@ -37,6 +38,19 @@ import { InstallShellScriptAction, UninstallShellScriptAction } from 'vs/workben
3738
registerAction2(QuickSwitchWindowAction);
3839
registerAction2(CloseWindowAction);
3940

41+
if (isMacintosh) {
42+
// macOS: behave like other native apps that have documents
43+
// but can run without a document opened and allow to close
44+
// the window when the last document is closed
45+
// (https://github.com/microsoft/vscode/issues/126042)
46+
KeybindingsRegistry.registerKeybindingRule({
47+
id: CloseWindowAction.ID,
48+
weight: KeybindingWeight.WorkbenchContrib,
49+
when: ContextKeyExpr.and(EditorsVisibleContext.toNegated(), SingleEditorGroupsContext),
50+
primary: KeyMod.CtrlCmd | KeyCode.KEY_W
51+
});
52+
}
53+
4054
// Actions: Install Shell Script (macOS only)
4155
if (isMacintosh) {
4256
registerAction2(InstallShellScriptAction);

0 commit comments

Comments
 (0)