aboutsummaryrefslogtreecommitdiff
path: root/bundle/src
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-22 02:46:30 +0000
committer_ov4 <ov4@ov4.org>2026-10-22 02:46:30 +0000
commit77098c720639a421f81ee14e47250d167d7af7bd (patch)
treedcf4d021f7828e34d9f463b8cf5159326617f242 /bundle/src
parent9efee50d405b8ca990d30114fb6ec6a57e2e92f1 (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'bundle/src')
-rw-r--r--bundle/src/main.js28
1 files changed, 20 insertions, 8 deletions
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();