From 77098c720639a421f81ee14e47250d167d7af7bd Mon Sep 17 00:00:00 2001 From: _ov4 Date: Thu, 22 Oct 2026 02:46:30 +0000 Subject: feat(bundle): add a native menu bar listing the shortcuts One Tauri menu definition serves the macOS menu bar and the top of each window on Windows. Menu clicks run the same frontend commands as the keyboard shortcuts in the focused window. Co-Authored-By: Claude Opus 5.5 --- bundle/src/main.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'bundle/src') diff --git a/bundle/src/main.js b/bundle/src/main.js index 4d06998..9a78ae7 100644 --- a/bundle/src/main.js +++ b/bundle/src/main.js @@ -136,14 +136,25 @@ async function action(callback) { busy = true; try { await callback(); } catch (error) { report(error); } finally { busy = false; } } -// CtrlCmd is Cmd on macOS and Ctrl elsewhere, matching Monaco's own keybindings. -const shortcuts = [ - [KeyMod.CtrlCmd | KeyCode.KeyN, () => action(newFile)], +function editorAction(id) { editor.focus(); editor.getAction(id).run(); } +// Keyed by the menu item ids in src-tauri/src/menu.rs. +const commands = { + new: () => action(newFile), // Each window is an independent native OS window, even while this one runs. - [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KeyN, () => invoke('new_window').catch(report)], - [KeyMod.CtrlCmd | KeyCode.KeyO, () => action(openFile)], - [KeyMod.CtrlCmd | KeyCode.KeyS, () => action(saveFile)], - [KeyMod.CtrlCmd | KeyCode.KeyF, () => { editor.focus(); editor.getAction('actions.find').run(); }] + new_window: () => invoke('new_window').catch(report), + open: () => action(openFile), + save: () => action(saveFile), + find: () => editorAction('actions.find'), + comment: () => editorAction('editor.action.commentLine') +}; +// CtrlCmd is Cmd on macOS and Ctrl elsewhere, matching Monaco's own keybindings and the menu. +const shortcuts = [ + [KeyMod.CtrlCmd | KeyCode.KeyN, 'new'], + [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KeyN, 'new_window'], + [KeyMod.CtrlCmd | KeyCode.KeyO, 'open'], + [KeyMod.CtrlCmd | KeyCode.KeyS, 'save'], + [KeyMod.CtrlCmd | KeyCode.KeyF, 'find'], + [KeyMod.CtrlCmd | KeyCode.Slash, 'comment'] ]; try { @@ -166,8 +177,9 @@ try { const shortcut = shortcuts.find(([binding]) => key.equals(binding)); if (!shortcut) return; event.preventDefault(); - shortcut[1](); + commands[shortcut[1]](); }); + await window.listen('menu', event => commands[event.payload]()); await window.onCloseRequested(async event => { if (closing) return; event.preventDefault(); -- cgit v1.3.1-4-g156e