diff --git a/capi/src/io.rs b/capi/src/io.rs index 7c853015..3a3e242b 100644 --- a/capi/src/io.rs +++ b/capi/src/io.rs @@ -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. diff --git a/capi/src/lib.rs b/capi/src/lib.rs index b6f06432..31981e74 100644 --- a/capi/src/lib.rs +++ b/capi/src/lib.rs @@ -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; } diff --git a/capi/src/symbols-elf.map b/capi/src/symbols-elf.map index b60033c3..41bec920 100644 --- a/capi/src/symbols-elf.map +++ b/capi/src/symbols-elf.map @@ -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; diff --git a/capi/src/symbols-mach_o.map b/capi/src/symbols-mach_o.map index d5ae7f5c..374e149a 100644 --- a/capi/src/symbols-mach_o.map +++ b/capi/src/symbols-mach_o.map @@ -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 diff --git a/capi/src/symbols-msvc.def b/capi/src/symbols-msvc.def index 230e20cc..3e75d062 100644 --- a/capi/src/symbols-msvc.def +++ b/capi/src/symbols-msvc.def @@ -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; diff --git a/include/chewing.h b/include/chewing.h index b25591fd..2accffa2 100644 --- a/include/chewing.h +++ b/include/chewing.h @@ -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 * diff --git a/src/editor/mod.rs b/src/editor/mod.rs index 5128bd6f..9d611220 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -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(); } diff --git a/tests/test-bopomofo.c b/tests/test-bopomofo.c index 2fa7cd2b..daabf0ff 100644 --- a/tests/test-bopomofo.c +++ b/tests/test-bopomofo.c @@ -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"); + ok_commit_buffer(ctx, "測試"); + + chewing_ack(ctx); + ok_commit_buffer(ctx, ""); + + chewing_delete(ctx); +} + void test_get_phoneSeq() { static const struct { @@ -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();