Skip to content

Commit 2adf248

Browse files
committed
fix(ui): addKeyboardShortcut codegen drops 3-arg calls (modifiers slot missing)
The PERRY_UI_TABLE entry for addKeyboardShortcut declared only 2 args (Str + Closure), but the runtime FFI takes 3 (key, modifiers, callback) and every documented example uses the 3-arg form. lower_perry_ui_table_call hits its arity-mismatch fallback at lower_call.rs:5327 and silently returns 0.0 — no menu item is installed and no shortcut fires. Add the missing UiArgKind::F64 modifier slot so codegen, runtime, and docs all line up. Also update types/perry/ui/index.d.ts to declare the 3-arg form with a doc comment for the modifier bitmap (1=Cmd, 2=Shift, 4=Option, 8=Control), matching the macos/gtk4/windows runtime implementations. Verified by recompiling perry-pry: all 7 keyboard shortcuts (Cmd+L, Cmd+F, Cmd+1, Cmd+2, Cmd+I, Cmd+V, Escape) now appear in the app menu and their callbacks fire on key press, where previously the app menu only showed the default Quit item.
1 parent e5bc172 commit 2adf248

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

crates/perry-codegen/src/lower_call.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5146,8 +5146,9 @@ const PERRY_UI_TABLE: &[UiSig] = &[
51465146
args: &[], ret: UiReturnKind::F64 },
51475147

51485148
// ---- Keyboard shortcuts ----
5149+
// `modifiers` is a bitfield: 1=Cmd, 2=Shift, 4=Option, 8=Control.
51495150
UiSig { method: "addKeyboardShortcut", runtime: "perry_ui_add_keyboard_shortcut",
5150-
args: &[UiArgKind::Str, UiArgKind::Closure], ret: UiReturnKind::Void },
5151+
args: &[UiArgKind::Str, UiArgKind::F64, UiArgKind::Closure], ret: UiReturnKind::Void },
51515152

51525153
// ---- App lifecycle hooks ----
51535154
UiSig { method: "onTerminate", runtime: "perry_ui_app_on_terminate",

types/perry/ui/index.d.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,21 @@ export function pollOpenFile(): string;
521521
// Keyboard shortcuts
522522
// ---------------------------------------------------------------------------
523523

524-
export function addKeyboardShortcut(key: string, callback: () => void): void;
524+
/**
525+
* Register a keyboard shortcut that fires `callback` when pressed.
526+
*
527+
* `modifiers` is a bitfield: `1 = Cmd` (Ctrl on Linux/Windows), `2 = Shift`,
528+
* `4 = Option/Alt`, `8 = Control`. Combine with bitwise OR — e.g. Cmd+Shift+S
529+
* is `1 | 2` (= `3`). Pass `0` for an unmodified key.
530+
*
531+
* Must be called before `App({...})` — registrations are buffered and
532+
* installed when the menu bar is created.
533+
*/
534+
export function addKeyboardShortcut(
535+
key: string,
536+
modifiers: number,
537+
callback: () => void,
538+
): void;
525539

526540
// ---------------------------------------------------------------------------
527541
// App lifecycle hooks

0 commit comments

Comments
 (0)