History

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

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 33433031 parent d5ba68f1 file · +9 −0Browse files

Unified · Split

apps/desktop/src/main/index.ts+9−0
@@ -853,9 +853,18 @@ const installApplicationMenu = () => { · 852 unmodified lines
853853 { role: "quit" },
854854 ],
855855 };
856+ // The close-window accelerator (Cmd+W on macOS, Ctrl+W elsewhere) lives on
857+ // the `close` role, which the File menu carries. The Window menu's role only
858+ // provides Minimize/Zoom/Front, so without an explicit File menu nothing
859+ // binds Cmd+W and the window can't be closed from the keyboard.
860+ const fileMenu: MenuItemConstructorOptions = {
861+ label: "File",
862+ submenu: [{ role: "close" }],
863+ };
856864 Menu.setApplicationMenu(
857865 Menu.buildFromTemplate([
858866 appMenu,
867+ fileMenu,
859868 { role: "editMenu" },
860869 { role: "viewMenu" },
861870 { role: "windowMenu" },