Skip to content

Commit

Permalink
Merge pull request #611 from chewing/feat-ack
Browse files Browse the repository at this point in the history
feat(capi): New API chewing_ack to acknowledge output buffers
  • Loading branch information
kanru authored Jul 15, 2024
2 parents 8c640c3 + d00d6a6 commit 2a23796
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 0 deletions.
10 changes: 10 additions & 0 deletions capi/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@ pub unsafe extern "C" fn chewing_Reset(ctx: *mut ChewingContext) -> c_int {
OK
}

/// # Safety
///
/// This function should be called with valid pointers.
#[no_mangle]
pub unsafe extern "C" fn chewing_ack(ctx: *mut ChewingContext) -> c_int {
let ctx = as_mut_or_return!(ctx, ERROR);
ctx.editor.ack();
OK
}

/// # Safety
///
/// This function should be called with valid pointers.
Expand Down
11 changes: 11 additions & 0 deletions capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,17 @@ pub mod output {
/// This function fails if the IM editor is not in entering state.
pub use super::io::chewing_clean_bopomofo_buf;

/// Acknowledge the commit buffer and aux output buffer.
///
/// Chewing automatically acknowledges and clear the output buffers after
/// processing new input events.
///
/// After handling the ephemeral output buffer like the commit buffer and
/// the aux output buffer, IM wrappers can proactively acknowledge and clear
/// the buffers. This can be used so that IM wrappers don't have to remember
/// whether an output has been handled or not.
pub use super::io::chewing_ack;

pub use super::public::IntervalType;
}

Expand Down
1 change: 1 addition & 0 deletions capi/src/symbols-elf.map
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ CHEWING_0.5 {

CHEWING_0.9 {
global:
chewing_ack;
chewing_config_has_option;
chewing_config_set_int;
chewing_config_get_int;
Expand Down
1 change: 1 addition & 0 deletions capi/src/symbols-mach_o.map
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ _chewing_userphrase_lookup
_chewing_userphrase_remove
_chewing_zuin_Check
_chewing_zuin_String
_chewing_ack
_chewing_config_has_option
_chewing_config_set_int
_chewing_config_get_int
Expand Down
1 change: 1 addition & 0 deletions capi/src/symbols-msvc.def
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ EXPORTS
chewing_userphrase_remove;
chewing_zuin_Check;
chewing_zuin_String;
chewing_ack;
chewing_config_has_option;
chewing_config_set_int;
chewing_config_get_int;
Expand Down
7 changes: 7 additions & 0 deletions include/chewing.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ void chewing_free(void *ptr);
*/
int chewing_Reset(struct ChewingContext *ctx);

/**
* # Safety
*
* This function should be called with valid pointers.
*/
int chewing_ack(struct ChewingContext *ctx);

/**
* # Safety
*
Expand Down
4 changes: 4 additions & 0 deletions src/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ impl Editor {
self.state = Box::new(Entering);
self.shared.clear();
}
pub fn ack(&mut self) {
self.shared.notice_buffer.clear();
self.shared.commit_buffer.clear();
}
pub fn clear_syllable_editor(&mut self) {
self.shared.syl.clear();
}
Expand Down
17 changes: 17 additions & 0 deletions tests/test-bopomofo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,22 @@ void test_SimpleEngine()
chewing_delete(ctx);
}

void test_Acknowledge()
{
ChewingContext *ctx;

ctx = chewing_new();
start_testcase(ctx, fd);

type_keystroke_by_string(ctx, "hk4g4<E>");
ok_commit_buffer(ctx, "測試");

chewing_ack(ctx);
ok_commit_buffer(ctx, "");

chewing_delete(ctx);
}

void test_get_phoneSeq()
{
static const struct {
Expand Down Expand Up @@ -2442,6 +2458,7 @@ int main(int argc, char *argv[])
test_FuzzySearchMode();
test_FuzzySearchMode_Hanyu();
test_SimpleEngine();
test_Acknowledge();

test_get_phoneSeq();
test_bopomofo_buffer();
Expand Down

0 comments on commit 2a23796

Please sign in to comment.