diff --git a/include/riti.h b/include/riti.h index a4206ae..ed1ab8e 100644 --- a/include/riti.h +++ b/include/riti.h @@ -280,6 +280,13 @@ RitiContext *riti_context_new_with_config(const Config *ptr); void riti_context_free(RitiContext *ptr); +/* + Generates suggestion for `key` press. + + `modifier`: state of modifier keys + `selection`: previously selected user selection index if available otherwise `0`. + It is used to preserve user's candidate selection if the key is a punctuation character in Phonetic method. + */ Suggestion *riti_get_suggestion_for_key(RitiContext *ptr, uint16_t key, uint8_t modifier, diff --git a/src/ffi.rs b/src/ffi.rs index 512a345..c338430 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -32,6 +32,11 @@ pub extern "C" fn riti_context_free(ptr: *mut RitiContext) { riti_free(ptr) } +/// Generates suggestion for `key` press. +/// +/// `modifier`: state of modifier keys +/// `selection`: previously selected user selection index if available otherwise `0`. +/// It is used to preserve user's candidate selection if the key is a punctuation character in Phonetic method. #[no_mangle] pub extern "C" fn riti_get_suggestion_for_key( ptr: *mut RitiContext, diff --git a/src/phonetic/method.rs b/src/phonetic/method.rs index 0ac698d..2a6ecb8 100644 --- a/src/phonetic/method.rs +++ b/src/phonetic/method.rs @@ -89,14 +89,10 @@ impl Method for PhoneticMethod { let mut suggestion = self.create_suggestion(data, config); // Preserve user's selection if the keypress was a punctuation mark - match suggestion { - Suggestion::Full { selection: ref mut sel, .. } => { - if matches!(character, '.' | '?' | '!' | ',' | ':' | ';' | '-' | '_' | ')' | '}' | ']' | '\'' | '"') { - *sel = selection.into(); - } + if let Suggestion::Full { selection: ref mut sel, .. } = suggestion { + if matches!(character, '.' | '?' | '!' | ',' | ':' | ';' | '-' | '_' | ')' | '}' | ']' | '\'' | '"') { + *sel = selection.into(); } - - _ => (), } suggestion