From 3005e5450339c6c3fbc1c7c67ab8008ed39ec864 Mon Sep 17 00:00:00 2001 From: "Ngo Iok Ui (Wu Yu Wei)" Date: Fri, 25 Nov 2022 14:30:28 +0800 Subject: [PATCH] On macOS, fix arrow keys misprint texts (#769) * On macOS, fix arrow keys misprint texts * Update mod.rs --- .changes/mac-arrow.md | 6 ++++++ src/webview/wkwebview/mod.rs | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .changes/mac-arrow.md diff --git a/.changes/mac-arrow.md b/.changes/mac-arrow.md new file mode 100644 index 000000000..9b7194243 --- /dev/null +++ b/.changes/mac-arrow.md @@ -0,0 +1,6 @@ +--- +"wry": patch +--- + +On macOS, fix arrow keys misprint text on textarea. + diff --git a/src/webview/wkwebview/mod.rs b/src/webview/wkwebview/mod.rs index 4d90ab78d..246c9ab53 100644 --- a/src/webview/wkwebview/mod.rs +++ b/src/webview/wkwebview/mod.rs @@ -307,8 +307,12 @@ impl InnerWebView { // So we pass the event to menu if we have one extern "C" fn key_down(this: &mut Object, _: Sel, event: id) { unsafe { - let superclass: *const Class = msg_send![this, superclass]; - let () = msg_send![super(this, &*superclass), keyDown: event]; + let keycode: u16 = msg_send![event, keyCode]; + // Arrow keys are handled by other event chains + if !(123..=126).contains(&keycode) { + let superclass: *const Class = msg_send![this, superclass]; + let () = msg_send![super(this, &*superclass), keyDown: event]; + } let app = cocoa::appkit::NSApp(); let menu: id = msg_send![app, mainMenu];