macos: add use_ime option to disable the IME

The IME stuff on macos tends to swallow repeats for some keys.
Ugh.  So this commit adds an option to disable the use of the IME.

Switching away from it effectively inverts the meanging of backspace
and delete (because our method is no longer called by the IME), so
we need to check for that and remap it.  Ugh.

Ugh.
This commit is contained in:
Wez Furlong committed 2020-01-05 22:54:59 -08:00
1 parent 94cac23df9
commit 180a991760
3 files changed
+32 -12

No files matched your search

+3
View File
@@ -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)]
+5
View File
@@ -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()
+24 -12
View File
@@ -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];