From 239945a13da4251437fdd4bf41b7c7013bf497c2 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Thu, 11 Nov 2010 16:01:18 +0800 Subject: [PATCH] Commit remaining input before deactive. --- scm/chewing.scm | 3 ++- src/chewing.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletions(-) diff --git a/scm/chewing.scm b/scm/chewing.scm index 0f652b6..04766a4 100644 --- a/scm/chewing.scm +++ b/scm/chewing.scm @@ -256,7 +256,8 @@ (if (chewing-press-key mc key key-state #t) #f (if (chewing-off-key? key key-state) - (begin + (let ((mid (chewing-context-mc-id mc))) + (chewing-lib-flush mid) (chewing-reset-handler mc) (im-clear-preedit mc) (im-deactivate-candidate-selector mc) diff --git a/src/chewing.c b/src/chewing.c index 2798d9b..ad40615 100644 --- a/src/chewing.c +++ b/src/chewing.c @@ -70,6 +70,7 @@ typedef struct chewing_context { int prev_page; int prev_cursor; int has_active_candwin; + int has_pending_input; } uim_chewing_context; static struct context { @@ -184,6 +185,7 @@ chewing_context_new() ucc->prev_page = -1; ucc->prev_cursor = -1; ucc->has_active_candwin = 0; + ucc->has_pending_input = 0; } return ucc; @@ -550,6 +552,7 @@ press_key_internal(uim_chewing_context *ucc, int ukey, int state, } else { return uim_scm_f(); } + ucc->has_pending_input = 1; return check_output(ucc); } @@ -655,6 +658,27 @@ focus_out_context(uim_lisp id_) } static uim_lisp +flush(uim_lisp id_) +{ + int id; + uim_chewing_context *ucc; + + id = uim_scm_c_int(id_); + ucc = get_chewing_context(id); + + if (!ucc) + return uim_scm_f(); + + if (ucc->has_pending_input) { + chewing_handle_Enter(ucc->cc); + check_output(ucc); + ucc->has_pending_input = 0; + } + + return uim_scm_t(); +} + +static uim_lisp get_nr_candidates(uim_lisp id_) { int id, nth; @@ -843,6 +867,7 @@ uim_plugin_instance_init(void) uim_scm_init_subr_1("chewing-lib-reset-context", reset_context); uim_scm_init_subr_1("chewing-lib-focus-in-context", focus_in_context); uim_scm_init_subr_1("chewing-lib-focus-out-context", focus_out_context); + uim_scm_init_subr_1("chewing-lib-flush", flush); uim_scm_init_subr_1("chewing-lib-get-nr-candidates", get_nr_candidates); uim_scm_init_subr_2("chewing-lib-get-nth-candidate", get_nth_candidate); uim_scm_init_subr_1("chewing-lib-get-nr-candidates-per-page", -- 1.7.2.3