Skip to content

Commit e0d9ad1

Browse files
committed
Two separate commands for ImeCommit and ImePreedit
1 parent e0ce6ca commit e0d9ad1

File tree

2 files changed

+38
-47
lines changed

2 files changed

+38
-47
lines changed

src/bridge/ui_commands.rs

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ use crate::{
2323
#[derive(Clone, Debug, AsRefStr)]
2424
pub enum SerialCommand {
2525
Keyboard(String),
26-
KeyboardAsIme {
27-
formatted: Option<String>,
26+
KeyboardImeCommit {
27+
formatted: String,
28+
raw: String,
29+
},
30+
KeyboardImePreedit {
2831
raw: String,
29-
commit: bool,
3032
cursor_offset: Option<(usize, usize)>,
3133
},
3234
MouseButton {
@@ -65,45 +67,38 @@ impl SerialCommand {
6567
.map(|_| ())
6668
.context("Input failed")
6769
}
68-
SerialCommand::KeyboardAsIme {
69-
formatted,
70-
commit,
71-
raw,
72-
cursor_offset,
73-
} => {
74-
if commit {
75-
// Notified ime commit event, the text is guaranteed not to be None.
76-
let text = formatted.unwrap();
77-
trace!("IME Input Sent: {}", &text);
78-
nvim.call(
79-
"nvim_exec_lua_lua",
80-
call_args![
81-
"neovide.commit_handler(...)",
82-
vec![Value::from(raw), Value::from(text)],
83-
],
84-
)
85-
.await
86-
.map(|_| ())
87-
.context("IME Commit failed")
88-
} else {
89-
trace!("IME Input Preedit");
70+
SerialCommand::KeyboardImeCommit { formatted, raw } => {
71+
// Notified ime commit event, the text is guaranteed not to be None.
72+
trace!("IME Input Sent: {}", &formatted);
73+
nvim.call(
74+
"nvim_exec_lua_lua",
75+
call_args![
76+
"neovide.commit_handler(...)",
77+
vec![Value::from(raw), Value::from(formatted)],
78+
],
79+
)
80+
.await
81+
.map(|_| ())
82+
.context("IME Commit failed")
83+
}
84+
SerialCommand::KeyboardImePreedit { raw, cursor_offset } => {
85+
trace!("IME Input Preedit");
9086

91-
let (start_col, end_col) = cursor_offset
92-
.map_or((Value::Nil, Value::Nil), |(start_col, end_col)| {
93-
(Value::from(start_col), Value::from(end_col))
94-
});
87+
let (start_col, end_col) = cursor_offset
88+
.map_or((Value::Nil, Value::Nil), |(start_col, end_col)| {
89+
(Value::from(start_col), Value::from(end_col))
90+
});
9591

96-
nvim.call(
97-
"nvim_exec_lua_fast",
98-
call_args![
99-
"neovide.preedit_handler(...)",
100-
vec![Value::from(raw), start_col, end_col],
101-
],
102-
)
103-
.await
104-
.map(|_| ())
105-
.context("IME Preedit failed")
106-
}
92+
nvim.call(
93+
"nvim_exec_lua_fast",
94+
call_args![
95+
"neovide.preedit_handler(...)",
96+
vec![Value::from(raw), start_col, end_col],
97+
],
98+
)
99+
.await
100+
.map(|_| ())
101+
.context("IME Preedit failed")
107102
}
108103
SerialCommand::MouseButton {
109104
button,

src/window/keyboard_manager.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,15 @@ impl KeyboardManager {
5959
}
6060
WindowEvent::Ime(Ime::Commit(text)) => {
6161
log::trace!("Ime commit {text}");
62-
send_ui(SerialCommand::KeyboardAsIme {
63-
formatted: Some(self.format_key_text(text, false)),
62+
send_ui(SerialCommand::KeyboardImeCommit {
63+
formatted: self.format_key_text(text, false),
6464
raw: text.to_owned(),
65-
commit: true,
66-
cursor_offset: None,
6765
});
6866
}
6967
WindowEvent::Ime(Ime::Preedit(text, cursor_offset)) => {
7068
self.ime_preedit = (text.to_string(), *cursor_offset);
71-
send_ui(SerialCommand::KeyboardAsIme {
72-
formatted: None,
69+
send_ui(SerialCommand::KeyboardImePreedit {
7370
raw: text.to_owned(),
74-
commit: false,
7571
cursor_offset: *cursor_offset,
7672
});
7773
}

0 commit comments

Comments
 (0)