@@ -23,10 +23,12 @@ use crate::{
2323#[ derive( Clone , Debug , AsRefStr ) ]
2424pub 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,
0 commit comments