Compare commits

...

3 Commits

View File

@ -54,7 +54,7 @@ pub mod c {
im: *const InputMethod) im: *const InputMethod)
{ {
let imservice = check_imservice(imservice, im).unwrap(); let imservice = check_imservice(imservice, im).unwrap();
imservice.preedit_string = String::new(); imservice.preedit_string = String::new(); // I don't think this is ever used. Remove it?
imservice.pending = IMProtocolState { imservice.pending = IMProtocolState {
active: true, active: true,
..IMProtocolState::default() ..IMProtocolState::default()
@ -84,7 +84,7 @@ pub mod c {
surrounding_text: into_cstring(text) surrounding_text: into_cstring(text)
.expect("Received invalid string") .expect("Received invalid string")
.expect("Received null string"), .expect("Received null string"),
surrounding_cursor: cursor, cursor,
..imservice.pending.clone() ..imservice.pending.clone()
}; };
} }
@ -146,10 +146,6 @@ pub mod c {
let active_changed = imservice.current.active ^ imservice.pending.active; let active_changed = imservice.current.active ^ imservice.pending.active;
imservice.current = imservice.pending.clone(); imservice.current = imservice.pending.clone();
imservice.pending = IMProtocolState {
active: imservice.current.active,
..IMProtocolState::default()
};
if active_changed { if active_changed {
if imservice.current.active { if imservice.current.active {
@ -314,7 +310,7 @@ impl TryFrom<u32> for ChangeCause {
#[derive(Clone)] #[derive(Clone)]
struct IMProtocolState { struct IMProtocolState {
surrounding_text: CString, surrounding_text: CString,
surrounding_cursor: u32, cursor: u32,
content_purpose: ContentPurpose, content_purpose: ContentPurpose,
content_hint: ContentHint, content_hint: ContentHint,
text_change_cause: ChangeCause, text_change_cause: ChangeCause,
@ -325,7 +321,7 @@ impl Default for IMProtocolState {
fn default() -> IMProtocolState { fn default() -> IMProtocolState {
IMProtocolState { IMProtocolState {
surrounding_text: CString::default(), surrounding_text: CString::default(),
surrounding_cursor: 0, // TODO: mark that there's no cursor cursor: 0, // TODO: mark that there's no cursor
content_hint: ContentHint::NONE, content_hint: ContentHint::NONE,
content_purpose: ContentPurpose::Normal, content_purpose: ContentPurpose::Normal,
text_change_cause: ChangeCause::InputMethod, text_change_cause: ChangeCause::InputMethod,
@ -344,7 +340,7 @@ pub struct IMService {
pending: IMProtocolState, pending: IMProtocolState,
current: IMProtocolState, // turn current into an idiomatic representation? current: IMProtocolState, // turn current into an idiomatic representation?
preedit_string: String, preedit_string: String, // I don't think this is ever used. Remove it?
serial: Wrapping<u32>, serial: Wrapping<u32>,
} }
@ -366,7 +362,7 @@ impl IMService {
state_manager, state_manager,
pending: IMProtocolState::default(), pending: IMProtocolState::default(),
current: IMProtocolState::default(), current: IMProtocolState::default(),
preedit_string: String::new(), preedit_string: String::new(), // I don't think this is ever used. Remove it?
serial: Wrapping(0u32), serial: Wrapping(0u32),
}); });
unsafe { unsafe {
@ -378,9 +374,14 @@ impl IMService {
imservice imservice
} }
pub fn commit_string(&self, text: &CString) -> Result<(), SubmitError> { pub fn commit_string(&mut self, text: &CString) -> Result<(), SubmitError> {
match self.current.active { match self.current.active {
true => { true => {
let cursor_position = self.pending.cursor.try_into().unwrap(); // Converts u32 of cursor to usize
self.pending
.surrounding_text
.insert_str(cursor_position, text);
self.pending.cursor += text.len() as u32;
unsafe { unsafe {
c::eek_input_method_commit_string(self.im, text.as_ptr()) c::eek_input_method_commit_string(self.im, text.as_ptr())
} }
@ -391,11 +392,16 @@ impl IMService {
} }
pub fn delete_surrounding_text( pub fn delete_surrounding_text(
&self, &mut self,
before: u32, after: u32, before: u32, after: u32,
) -> Result<(), SubmitError> { ) -> Result<(), SubmitError> {
match self.current.active { match self.current.active {
true => { true => {
let cursor_position: usize = self.pending.cursor.try_into().unwrap(); // Converts u32 of cursor to usize
self.pending.surrounding_text.replace_range(
cursor_position - (before as usize)..cursor_position + (after as usize),
"",
);
unsafe { unsafe {
c::eek_input_method_delete_surrounding_text( c::eek_input_method_delete_surrounding_text(
self.im, self.im,
@ -415,6 +421,7 @@ impl IMService {
c::eek_input_method_commit(self.im, self.serial.0) c::eek_input_method_commit(self.im, self.serial.0)
} }
self.serial += Wrapping(1u32); self.serial += Wrapping(1u32);
imservice_handle_done(self);
Ok(()) Ok(())
}, },
false => Err(SubmitError::NotActive), false => Err(SubmitError::NotActive),