Skip to content

Commit

Permalink
Apply clippy suggestion and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
mominul committed Dec 23, 2023
1 parent 1cf28d6 commit a68dd7c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
7 changes: 7 additions & 0 deletions include/riti.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 3 additions & 7 deletions src/phonetic/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a68dd7c

Please sign in to comment.