diff options
author | Peng Wu <alexepico@gmail.com> | 2014-07-14 11:06:15 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2014-07-14 11:06:15 +0800 |
commit | 0de259f2382df739af096ac07728ec7a2dd2b6ae (patch) | |
tree | 469074ad4ffbde312610386422ef4f73fe9dbfa4 | |
parent | 14394369bf5bf4f16c0f8a121e51eeb4316d1e9d (diff) | |
download | ibus-libzhuyin-0de259f2382df739af096ac07728ec7a2dd2b6ae.tar.gz ibus-libzhuyin-0de259f2382df739af096ac07728ec7a2dd2b6ae.tar.xz ibus-libzhuyin-0de259f2382df739af096ac07728ec7a2dd2b6ae.zip |
support auto shift cursor after choose candidate
-rw-r--r-- | src/ZYZBopomofoSymbolSection.cc | 2 | ||||
-rw-r--r-- | src/ZYZBuiltinSymbolSection.cc | 2 | ||||
-rw-r--r-- | src/ZYZPhoneticEditor.cc | 16 | ||||
-rw-r--r-- | src/ZYZPhoneticSection.cc | 33 | ||||
-rw-r--r-- | src/ZYZPhoneticSection.h | 4 |
5 files changed, 40 insertions, 17 deletions
diff --git a/src/ZYZBopomofoSymbolSection.cc b/src/ZYZBopomofoSymbolSection.cc index 8c34831..a12093b 100644 --- a/src/ZYZBopomofoSymbolSection.cc +++ b/src/ZYZBopomofoSymbolSection.cc @@ -91,7 +91,7 @@ int BopomofoSymbolSection::selectCandidate (guint index) { m_choice = m_candidates[index]; - return g_utf8_strlen (m_choice, -1);; + return 1; } }; diff --git a/src/ZYZBuiltinSymbolSection.cc b/src/ZYZBuiltinSymbolSection.cc index 0ed7136..2472604 100644 --- a/src/ZYZBuiltinSymbolSection.cc +++ b/src/ZYZBuiltinSymbolSection.cc @@ -90,7 +90,7 @@ int BuiltinSymbolSection::selectCandidate (guint index) { m_choice = m_candidates[index]; - return g_utf8_strlen (m_choice, -1); + return 1; } }; diff --git a/src/ZYZPhoneticEditor.cc b/src/ZYZPhoneticEditor.cc index 69c43fe..ccdf51f 100644 --- a/src/ZYZPhoneticEditor.cc +++ b/src/ZYZPhoneticEditor.cc @@ -406,13 +406,14 @@ gboolean PhoneticEditor::selectCandidate (guint index) { if (STATE_CANDIDATE_SHOWN == m_input_state) { - int retval = m_phonetic_section->selectCandidate (index); + int offset = m_phonetic_section->selectCandidate (index); + m_cursor += offset; m_input_state = STATE_INPUT; updateZhuyin (); update (); - return retval; + return TRUE; } if (STATE_BUILTIN_SYMBOL_SHOWN == m_input_state || @@ -421,16 +422,17 @@ PhoneticEditor::selectCandidate (guint index) STATE_USER_SYMBOL_SHOWN == m_input_state */) { SymbolSectionPtr symbols = m_symbol_sections[m_input_state]; - int retval = symbols->selectCandidate (index); + int offset = symbols->selectCandidate (index); erase_input_sequence (m_text, m_cursor, 1); insert_symbol (m_text, m_cursor, symbols->m_type, symbols->m_lookup, symbols->m_choice); + m_cursor += offset; m_input_state = STATE_INPUT; update (); - return retval; + return TRUE; } return FALSE; @@ -741,12 +743,8 @@ PhoneticEditor::prepareCandidates (void) update (); return TRUE; } else { - guint16 inner_cursor = 0; - zhuyin_get_zhuyin_key_rest_offset - (instance, cursor, &inner_cursor); - m_input_state = STATE_CANDIDATE_SHOWN; - m_phonetic_section->initCandidates (instance, inner_cursor); + m_phonetic_section->initCandidates (instance, cursor); update (); return TRUE; diff --git a/src/ZYZPhoneticSection.cc b/src/ZYZPhoneticSection.cc index b7a0e2d..a240a68 100644 --- a/src/ZYZPhoneticSection.cc +++ b/src/ZYZPhoneticSection.cc @@ -20,6 +20,7 @@ */ #include "ZYZPhoneticSection.h" +#include <assert.h> #include "ZYZhuyinProperties.h" #include "ZYTradSimpConverter.h" @@ -37,10 +38,14 @@ PhoneticSection::~PhoneticSection () bool PhoneticSection::initCandidates (zhuyin_instance_t * instance, - int offset) + int cursor) { m_instance = instance; - m_offset = offset; + m_cursor = cursor; + + guint16 offset = 0; + zhuyin_get_zhuyin_key_rest_offset + (instance, cursor, &offset); zhuyin_guess_candidates (m_instance, offset); @@ -93,12 +98,32 @@ PhoneticSection::fillLookupTableByPage () int PhoneticSection::selectCandidate (guint index) { + guint16 prev_pos = m_cursor, cur_pos = 0; + ChewingKeyRest * key_rest = NULL; + lookup_candidate_t * candidate = NULL; zhuyin_get_candidate (m_instance, index, &candidate); - int retval = zhuyin_choose_candidate (m_instance, m_offset, candidate); + guint16 offset = 0; + zhuyin_get_zhuyin_key_rest_offset + (m_instance, m_cursor, &offset); + + offset = zhuyin_choose_candidate + (m_instance, offset, candidate); + + guint len = 0; + zhuyin_get_n_zhuyin (m_instance, &len); + + if (offset < len) { + zhuyin_get_zhuyin_key_rest (m_instance, offset, &key_rest); + zhuyin_get_zhuyin_key_rest_positions + (m_instance, key_rest, &cur_pos, NULL); + } else { + assert (offset == len); + cur_pos = zhuyin_get_parsed_input_length (m_instance); + } - return retval - m_offset; + return cur_pos - prev_pos; } }; diff --git a/src/ZYZPhoneticSection.h b/src/ZYZPhoneticSection.h index 9033cf6..3fcd565 100644 --- a/src/ZYZPhoneticSection.h +++ b/src/ZYZPhoneticSection.h @@ -35,7 +35,7 @@ public: public: virtual bool initCandidates (zhuyin_instance_t * instance, - int offset); + int cursor); virtual bool fillLookupTableByPage (); virtual int selectCandidate (guint index); @@ -48,7 +48,7 @@ protected: /* other variables. */ zhuyin_instance_t * m_instance; - int m_offset; + int m_cursor; }; }; |