Compare commits
3 Commits
main
...
Fixed_im_s
| Author | SHA1 | Date | |
|---|---|---|---|
| 09f7835eb9 | |||
| dd80c59aea | |||
| b8a35530af |
@ -54,7 +54,7 @@ pub mod c {
|
||||
im: *const InputMethod)
|
||||
{
|
||||
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 {
|
||||
active: true,
|
||||
..IMProtocolState::default()
|
||||
@ -84,7 +84,7 @@ pub mod c {
|
||||
surrounding_text: into_cstring(text)
|
||||
.expect("Received invalid string")
|
||||
.expect("Received null string"),
|
||||
surrounding_cursor: cursor,
|
||||
cursor,
|
||||
..imservice.pending.clone()
|
||||
};
|
||||
}
|
||||
@ -146,10 +146,6 @@ pub mod c {
|
||||
let active_changed = imservice.current.active ^ imservice.pending.active;
|
||||
|
||||
imservice.current = imservice.pending.clone();
|
||||
imservice.pending = IMProtocolState {
|
||||
active: imservice.current.active,
|
||||
..IMProtocolState::default()
|
||||
};
|
||||
|
||||
if active_changed {
|
||||
if imservice.current.active {
|
||||
@ -314,7 +310,7 @@ impl TryFrom<u32> for ChangeCause {
|
||||
#[derive(Clone)]
|
||||
struct IMProtocolState {
|
||||
surrounding_text: CString,
|
||||
surrounding_cursor: u32,
|
||||
cursor: u32,
|
||||
content_purpose: ContentPurpose,
|
||||
content_hint: ContentHint,
|
||||
text_change_cause: ChangeCause,
|
||||
@ -325,7 +321,7 @@ impl Default for IMProtocolState {
|
||||
fn default() -> IMProtocolState {
|
||||
IMProtocolState {
|
||||
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_purpose: ContentPurpose::Normal,
|
||||
text_change_cause: ChangeCause::InputMethod,
|
||||
@ -344,7 +340,7 @@ pub struct IMService {
|
||||
|
||||
pending: IMProtocolState,
|
||||
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>,
|
||||
}
|
||||
|
||||
@ -366,7 +362,7 @@ impl IMService {
|
||||
state_manager,
|
||||
pending: 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),
|
||||
});
|
||||
unsafe {
|
||||
@ -378,9 +374,14 @@ impl 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 {
|
||||
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 {
|
||||
c::eek_input_method_commit_string(self.im, text.as_ptr())
|
||||
}
|
||||
@ -391,11 +392,16 @@ impl IMService {
|
||||
}
|
||||
|
||||
pub fn delete_surrounding_text(
|
||||
&self,
|
||||
&mut self,
|
||||
before: u32, after: u32,
|
||||
) -> Result<(), SubmitError> {
|
||||
match self.current.active {
|
||||
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 {
|
||||
c::eek_input_method_delete_surrounding_text(
|
||||
self.im,
|
||||
@ -415,6 +421,7 @@ impl IMService {
|
||||
c::eek_input_method_commit(self.im, self.serial.0)
|
||||
}
|
||||
self.serial += Wrapping(1u32);
|
||||
imservice_handle_done(self);
|
||||
Ok(())
|
||||
},
|
||||
false => Err(SubmitError::NotActive),
|
||||
|
||||
Reference in New Issue
Block a user