diff --git a/.changes/wkwebview.md b/.changes/wkwebview.md new file mode 100644 index 000000000..0cc876944 --- /dev/null +++ b/.changes/wkwebview.md @@ -0,0 +1,5 @@ +--- +"wry": patch +--- + +On `macOS`, fix menu keyboard shortcuts. This issue bug was introduced in `v2` when added `webview` as `child`. diff --git a/src/wkwebview/mod.rs b/src/wkwebview/mod.rs index 0607e2b72..cd929b4fa 100644 --- a/src/wkwebview/mod.rs +++ b/src/wkwebview/mod.rs @@ -342,6 +342,10 @@ impl InnerWebView { sel!(acceptsFirstMouse:), accept_first_mouse as extern "C" fn(&Object, Sel, id) -> BOOL, ); + decl.add_method( + sel!(performKeyEquivalent:), + key_equivalent as extern "C" fn(&mut Object, Sel, id) -> BOOL, + ); extern "C" fn accept_first_mouse(this: &Object, _sel: Sel, _event: id) -> BOOL { unsafe { @@ -353,7 +357,17 @@ impl InnerWebView { } } } + + extern "C" fn key_equivalent(_this: &mut Object, _sel: Sel, event: id) -> BOOL { + unsafe { + let app = cocoa::appkit::NSApp(); + let menu: id = msg_send![app, mainMenu]; + let () = msg_send![menu, performKeyEquivalent: event]; + } + YES + } } + decl.register() } _ => class!(WryWebView),