diff --git a/src/engine.c b/src/engine.c index 2fffad0..95a4a62 100644 --- a/src/engine.c +++ b/src/engine.c @@ -89,6 +89,12 @@ static void ibus_hangul_engine_property_hide const gchar *prop_name); #endif +static void ibus_hangul_engine_candidate_clicked + (IBusEngine *engine, + guint index, + guint button, + guint state); + static void ibus_hangul_engine_flush (IBusHangulEngine *hangul); static void ibus_hangul_engine_update_preedit_text (IBusHangulEngine *hangul); @@ -234,6 +240,8 @@ ibus_hangul_engine_class_init (IBusHangulEngineClass *klass) engine_class->cursor_down = ibus_hangul_engine_cursor_down; engine_class->property_activate = ibus_hangul_engine_property_activate; + + engine_class->candidate_clicked = ibus_hangul_engine_candidate_clicked; } static void @@ -342,6 +350,11 @@ ibus_hangul_engine_update_preedit_text (IBusHangulEngine *hangul) ustring_append_ucs4 (preedit, hic_preedit, -1); if (ustring_length(preedit) > 0) { + IBusPreeditFocusMode preedit_option = IBUS_ENGINE_PREEDIT_COMMIT; + + if (hangul->hanja_list != NULL) + preedit_option = IBUS_ENGINE_PREEDIT_CLEAR; + text = ibus_text_new_from_ucs4 ((gunichar*)preedit->data); // ibus-hangul's internal preedit string ibus_text_append_attribute (text, IBUS_ATTR_TYPE_UNDERLINE, @@ -356,7 +369,7 @@ ibus_hangul_engine_update_preedit_text (IBusHangulEngine *hangul) text, ibus_text_get_length (text), TRUE, - IBUS_ENGINE_PREEDIT_COMMIT); + preedit_option); } else { text = ibus_text_new_from_static_string (""); ibus_engine_update_preedit_text ((IBusEngine *)hangul, text, 0, FALSE); @@ -492,6 +505,9 @@ ibus_hangul_engine_update_lookup_table (IBusHangulEngine *hangul) ibus_hangul_engine_update_hanja_list (hangul); if (hangul->hanja_list != NULL) { + // We should redraw preedit text with IBUS_ENGINE_PREEDIT_CLEAR option + // here to prevent committing it on focus out event incidentally. + ibus_hangul_engine_update_preedit_text (hangul); ibus_hangul_engine_apply_hanja_list (hangul); } else { ibus_hangul_engine_hide_lookup_table (hangul); @@ -505,6 +521,12 @@ ibus_hangul_engine_process_candidate_key_event (IBusHangulEngine *hangul, { if (keyval == IBUS_Escape) { ibus_hangul_engine_hide_lookup_table (hangul); + // When the lookup table is poped up, preedit string is + // updated with IBUS_ENGINE_PREEDIT_CLEAR option. + // So, when focus is out, the preedit text will not be committed. + // To prevent this problem, we have to update preedit text here + // with IBUS_ENGINE_PREEDIT_COMMIT option. + ibus_hangul_engine_update_preedit_text (hangul); return TRUE; } else if (keyval == IBUS_Return) { ibus_hangul_engine_commit_current_candidate (hangul); @@ -740,17 +762,16 @@ ibus_hangul_engine_flush (IBusHangulEngine *hangul) ustring_append_ucs4 (hangul->preedit, str, -1); - if (ustring_length (hangul->preedit) == 0) - return; + if (ustring_length (hangul->preedit) != 0) { + str = ustring_begin (hangul->preedit); + text = ibus_text_new_from_ucs4 (str); - str = ustring_begin (hangul->preedit); - text = ibus_text_new_from_ucs4 (str); + ibus_engine_commit_text ((IBusEngine *) hangul, text); - ibus_engine_hide_preedit_text ((IBusEngine *) hangul); - // Use ibus_engine_update_preedit_text_with_mode instead. - //ibus_engine_commit_text ((IBusEngine *) hangul, text); + ustring_clear(hangul->preedit); + } - ustring_clear(hangul->preedit); + ibus_hangul_engine_update_preedit_text (hangul); } static void @@ -766,6 +787,8 @@ ibus_hangul_engine_focus_in (IBusEngine *engine) ibus_engine_register_properties (engine, hangul->prop_list); + ibus_hangul_engine_update_preedit_text (hangul); + if (hangul->hanja_list != NULL) { ibus_hangul_engine_update_lookup_table_ui (hangul); } @@ -779,7 +802,11 @@ ibus_hangul_engine_focus_out (IBusEngine *engine) IBusHangulEngine *hangul = (IBusHangulEngine *) engine; if (hangul->hanja_list == NULL) { - ibus_hangul_engine_flush (hangul); + // ibus-hangul uses + // ibus_engine_update_preedit_text_with_mode() function which makes + // the preedit string committed automatically when the focus is out. + // So we don't need to commit the preedit here. + hangul_ic_reset (hangul->context); } else { ibus_engine_hide_lookup_table (engine); ibus_engine_hide_auxiliary_text (engine); @@ -794,9 +821,6 @@ ibus_hangul_engine_reset (IBusEngine *engine) IBusHangulEngine *hangul = (IBusHangulEngine *) engine; ibus_hangul_engine_flush (hangul); - if (hangul->hanja_list != NULL) { - ibus_hangul_engine_hide_lookup_table (hangul); - } parent_class->reset (engine); } @@ -972,3 +996,26 @@ key_event_list_match(GArray* list, guint keyval, guint modifiers) return FALSE; } + +static void +ibus_hangul_engine_candidate_clicked (IBusEngine *engine, + guint index, + guint button, + guint state) +{ + IBusHangulEngine *hangul = (IBusHangulEngine *) engine; + if (hangul == NULL) + return; + + if (hangul->table == NULL) + return; + + ibus_lookup_table_set_cursor_pos (hangul->table, index); + ibus_hangul_engine_commit_current_candidate (hangul); + + if (hangul->hanja_mode) { + ibus_hangul_engine_update_lookup_table (hangul); + } else { + ibus_hangul_engine_hide_lookup_table (hangul); + } +}