diff --git a/src/config/mod.rs b/src/config/mod.rs index b07efdff9..80796af06 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -467,6 +467,9 @@ pub struct Config { /// to the terminal. #[serde(default = "default_true")] pub scroll_to_bottom_on_input: bool, + + #[serde(default = "default_true")] + pub use_ime: bool, } #[derive(Deserialize, Clone, Copy, Debug)] diff --git a/src/main.rs b/src/main.rs index e57bd29f5..b70b9fad5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -705,6 +705,11 @@ fn run() -> anyhow::Result<()> { Ok(config) => config, }; + #[cfg(target_os = "macos")] + { + window::os::macos::use_ime(config.use_ime); + } + match opts .cmd .as_ref() diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index 16b74418f..39e28c4b2 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -28,6 +28,13 @@ use std::any::Any; use std::cell::RefCell; use std::ffi::c_void; use std::rc::Rc; +use std::sync::atomic::{AtomicBool, Ordering}; + +static USE_IME: AtomicBool = AtomicBool::new(false); + +pub fn use_ime(enable: bool) { + USE_IME.store(enable, Ordering::Relaxed); +} #[repr(C)] struct NSRange(cocoa::foundation::NSRange); @@ -590,9 +597,11 @@ impl WindowOpsMut for WindowInner { if let Some(window_view) = WindowView::get_this(unsafe { &**self.view }) { window_view.inner.borrow_mut().text_cursor_position = cursor; } - unsafe { - let input_context: id = msg_send![&**self.view, inputContext]; - let () = msg_send![input_context, invalidateCharacterCoordinates]; + if USE_IME.load(Ordering::Relaxed) { + unsafe { + let input_context: id = msg_send![&**self.view, inputContext]; + let () = msg_send![input_context, invalidateCharacterCoordinates]; + } } } } @@ -1016,16 +1025,19 @@ impl WindowView { // `Fn-Delete` emits DEL. // Alt-Delete is mapped by the IME to be equivalent to Fn-Delete. // We want to emit Alt-BS in that situation. - let unmod = - if virtual_key == super::keycodes::kVK_Delete && modifiers.contains(Modifiers::ALT) { - "\x08" - } else if virtual_key == super::keycodes::kVK_Tab { - "\t" - } else { - unmod - }; + let unmod = if virtual_key == super::keycodes::kVK_Delete + && modifiers.contains(Modifiers::ALT) + { + "\x08" + } else if virtual_key == super::keycodes::kVK_Tab { + "\t" + } else if !USE_IME.load(Ordering::Relaxed) && virtual_key == super::keycodes::kVK_Delete { + "\x08" + } else { + unmod + }; - if modifiers.is_empty() { + if USE_IME.load(Ordering::Relaxed) && modifiers.is_empty() { unsafe { let input_context: id = msg_send![this, inputContext]; let res: BOOL = msg_send![input_context, handleEvent: nsevent];