History

fix(desktop): bind Cmd+W to close the window

The application menu had no File menu, so the close-window role (which carries the Cmd+W / Ctrl+W accelerator) was never registered. The Window menu role only provides Minimize, Zoom, and Bring All to Front, so there was no keyboard shortcut to close the window. Add a File menu with the close role to restore the standard accelerator on every platform.

Rhys Sullivan committed 4 months ago

Commit 85693f21 parent eb9ed891 file · +9 −0Browse files

Unified · Split

apps/desktop/src/main/index.ts+9−0
@@ -846,9 +846,18 @@ const installApplicationMenu = () => { · 845 unmodified lines
846846 { role: "quit" },
847847 ],
848848 };
849+ // The close-window accelerator (Cmd+W on macOS, Ctrl+W elsewhere) lives on
850+ // the `close` role, which the File menu carries. The Window menu's role only
851+ // provides Minimize/Zoom/Front, so without an explicit File menu nothing
852+ // binds Cmd+W and the window can't be closed from the keyboard.
853+ const fileMenu: MenuItemConstructorOptions = {
854+ label: "File",
855+ submenu: [{ role: "close" }],
856+ };
849857 Menu.setApplicationMenu(
850858 Menu.buildFromTemplate([
851859 appMenu,
860+ fileMenu,
852861 { role: "editMenu" },
853862 { role: "viewMenu" },
854863 { role: "windowMenu" },