From 67fde7c1e1e15dc29e74849bc3ed3cff03aac78f Mon Sep 17 00:00:00 2001 From: Rhys Sullivan <39114868+RhysSullivan@users.noreply.github.com> Date: Tue, 30 Jun 2026 11:23:30 -0700 Subject: [PATCH] Bind Cmd+[ / Cmd+] to back/forward in the desktop app The desktop window loads the web shell, which navigates with browser history (TanStack Router pushState). On the web the browser chrome handles the standard back/forward keys, but in the Electron window there is no chrome, and the app menu is built entirely from roles, none of which carry Back/Forward. Electron binds none of these shortcuts by default, so Cmd+[ and Cmd+] were dead keys. Add a History menu with Back (Cmd+[) and Forward (Cmd+]), Ctrl+[ / Ctrl+] on Windows/Linux, driving the focused window's navigation history. The canGoBack/canGoForward guards make the keys no-ops at the ends of the stack, matching how they behave in a browser. --- apps/desktop/src/main/index.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts index 361388fe8..fcfcf4149 100644 --- a/apps/desktop/src/main/index.ts +++ b/apps/desktop/src/main/index.ts @@ -989,12 +989,44 @@ const installApplicationMenu = () => { label: "File", submenu: [{ role: "close" }], }; + // The web shell navigates with browser history (TanStack Router pushState), + // but Electron binds none of the history shortcuts by default and the menu is + // built from roles, none of which carry Back/Forward. So the standard macOS + // Cmd+[ / Cmd+] (Ctrl+[ / Ctrl+] elsewhere) are dead keys inside the desktop + // window, with no browser chrome to fall back on. Bind them here, driving the + // focused window's navigation history. canGo* guards keep the keys no-ops at + // the ends of the stack, matching how they behave in a browser. + const navigateHistory = (direction: "back" | "forward") => { + const nav = BrowserWindow.getFocusedWindow()?.webContents.navigationHistory; + if (!nav) return; + if (direction === "back") { + if (nav.canGoBack()) nav.goBack(); + } else if (nav.canGoForward()) { + nav.goForward(); + } + }; + const historyMenu: MenuItemConstructorOptions = { + label: "History", + submenu: [ + { + label: "Back", + accelerator: "CmdOrCtrl+[", + click: () => navigateHistory("back"), + }, + { + label: "Forward", + accelerator: "CmdOrCtrl+]", + click: () => navigateHistory("forward"), + }, + ], + }; Menu.setApplicationMenu( Menu.buildFromTemplate([ appMenu, fileMenu, { role: "editMenu" }, { role: "viewMenu" }, + historyMenu, { role: "windowMenu" }, ]), );