From 74c82098624305f3b2c4a0b792da15e83d712fb9 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 11 Jun 2021 15:14:29 +0200 Subject: [PATCH] macos - restore Cmd+W to close window when no editors opened --- .../electron-sandbox/actions/windowActions.ts | 4 +++- .../electron-sandbox/desktop.contribution.ts | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/electron-sandbox/actions/windowActions.ts b/src/vs/workbench/electron-sandbox/actions/windowActions.ts index e6dbac49746c5..67fd94f32dea7 100644 --- a/src/vs/workbench/electron-sandbox/actions/windowActions.ts +++ b/src/vs/workbench/electron-sandbox/actions/windowActions.ts @@ -27,9 +27,11 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis export class CloseWindowAction extends Action2 { + static readonly ID = 'workbench.action.closeWindow'; + constructor() { super({ - id: 'workbench.action.closeWindow', + id: CloseWindowAction.ID, title: { value: localize('closeWindow', "Close Window"), mnemonicTitle: localize({ key: 'miCloseWindow', comment: ['&& denotes a mnemonic'] }, "Clos&&e Window"), diff --git a/src/vs/workbench/electron-sandbox/desktop.contribution.ts b/src/vs/workbench/electron-sandbox/desktop.contribution.ts index 01564b51c732b..59b1afc670988 100644 --- a/src/vs/workbench/electron-sandbox/desktop.contribution.ts +++ b/src/vs/workbench/electron-sandbox/desktop.contribution.ts @@ -23,6 +23,7 @@ import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } fr import { PartsSplash } from 'vs/workbench/electron-sandbox/splash'; import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; import { InstallShellScriptAction, UninstallShellScriptAction } from 'vs/workbench/electron-sandbox/actions/installActions'; +import { EditorsVisibleContext, SingleEditorGroupsContext } from 'vs/workbench/common/editor'; // Actions (function registerActions(): void { @@ -37,6 +38,19 @@ import { InstallShellScriptAction, UninstallShellScriptAction } from 'vs/workben registerAction2(QuickSwitchWindowAction); registerAction2(CloseWindowAction); + if (isMacintosh) { + // macOS: behave like other native apps that have documents + // but can run without a document opened and allow to close + // the window when the last document is closed + // (https://github.com/microsoft/vscode/issues/126042) + KeybindingsRegistry.registerKeybindingRule({ + id: CloseWindowAction.ID, + weight: KeybindingWeight.WorkbenchContrib, + when: ContextKeyExpr.and(EditorsVisibleContext.toNegated(), SingleEditorGroupsContext), + primary: KeyMod.CtrlCmd | KeyCode.KEY_W + }); + } + // Actions: Install Shell Script (macOS only) if (isMacintosh) { registerAction2(InstallShellScriptAction);