diff options
author | Peng Wu <alexepico@gmail.com> | 2016-06-23 14:20:30 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2016-06-23 14:20:30 +0800 |
commit | b8f479255bb36a85aada85537ee7e37a9f2e233b (patch) | |
tree | 7e3e633f465803d8b984b166e6e3bf1980a82031 /src/PYPPhoneticEditor.cc | |
parent | 5e1ee95409c71542b8bb6dff4f88b27d9bc279cf (diff) | |
download | ibus-libpinyin-b8f479255bb36a85aada85537ee7e37a9f2e233b.tar.gz ibus-libpinyin-b8f479255bb36a85aada85537ee7e37a9f2e233b.tar.xz ibus-libpinyin-b8f479255bb36a85aada85537ee7e37a9f2e233b.zip |
update class PhoneticEditor
Diffstat (limited to 'src/PYPPhoneticEditor.cc')
-rw-r--r-- | src/PYPPhoneticEditor.cc | 61 |
1 files changed, 14 insertions, 47 deletions
diff --git a/src/PYPPhoneticEditor.cc b/src/PYPPhoneticEditor.cc index 82e52be..d6ac3d9 100644 --- a/src/PYPPhoneticEditor.cc +++ b/src/PYPPhoneticEditor.cc @@ -337,11 +337,9 @@ PhoneticEditor::commit (const gchar *str) guint PhoneticEditor::getPinyinCursor () { - guint len = 0; - /* Translate cursor position to pinyin position. */ - guint16 pinyin_cursor = 0; - pinyin_get_pinyin_key_rest_offset (m_instance, m_cursor, &pinyin_cursor); + size_t pinyin_cursor = 0; + pinyin_get_pinyin_offset (m_instance, m_cursor, &pinyin_cursor); return pinyin_cursor; } @@ -349,12 +347,10 @@ PhoneticEditor::getPinyinCursor () guint PhoneticEditor::getLookupCursor (void) { - guint len = 0; - pinyin_get_n_pinyin (m_instance, &len); guint lookup_cursor = getPinyinCursor (); /* show candidates when pinyin cursor is at end. */ - if (lookup_cursor == len) + if (lookup_cursor == m_text.length ()) lookup_cursor = 0; return lookup_cursor; } @@ -386,9 +382,7 @@ PhoneticEditor::selectCandidate (guint i) pinyin_guess_sentence (m_instance); - len = 0; - pinyin_get_n_pinyin (m_instance, &len); - if (lookup_cursor == len) { + if (lookup_cursor == m_text.length ()) { pinyin_train (m_instance); commit (); return TRUE; @@ -497,37 +491,13 @@ PhoneticEditor::moveCursorToEnd (void) guint PhoneticEditor::getCursorLeftByWord (void) { - guint16 cursor = 0; - - if (G_UNLIKELY (m_cursor > m_pinyin_len)) { - cursor = m_pinyin_len; - } else { - guint len = 0; - pinyin_get_n_pinyin (m_instance, &len); - - guint pinyin_cursor = getPinyinCursor (); + size_t offset = 0; - PinyinKeyPos *pos = NULL; + pinyin_get_pinyin_offset (m_instance, m_cursor, &offset); - if (pinyin_cursor < len) { - pinyin_get_pinyin_key_rest (m_instance, pinyin_cursor, &pos); - - pinyin_get_pinyin_key_rest_positions - (m_instance, pos, &cursor, NULL); - } else { - /* at the end of pinyin string. */ - cursor = m_cursor; - } + size_t cursor = 0; - /* cursor at the begin of one pinyin */ - g_return_val_if_fail (pinyin_cursor > 0, 0); - if ( cursor == m_cursor) { - pinyin_get_pinyin_key_rest (m_instance, pinyin_cursor - 1, &pos); - - pinyin_get_pinyin_key_rest_positions - (m_instance, pos, &cursor, NULL); - } - } + pinyin_get_left_character_offset(m_instance, offset, &cursor); return cursor; } @@ -535,16 +505,13 @@ PhoneticEditor::getCursorLeftByWord (void) guint PhoneticEditor::getCursorRightByWord (void) { - guint16 cursor = 0; + size_t offset = 0; - if (G_UNLIKELY (m_cursor > m_pinyin_len)) { - cursor = m_text.length (); - } else { - guint pinyin_cursor = getPinyinCursor (); - PinyinKeyPos *pos = NULL; - pinyin_get_pinyin_key_rest (m_instance, pinyin_cursor, &pos); - pinyin_get_pinyin_key_rest_positions (m_instance, pos, NULL, &cursor); - } + pinyin_get_pinyin_offset (m_instance, m_cursor, &offset); + + size_t cursor = 0; + + pinyin_get_right_character_offset(m_instance, offset, &cursor); return cursor; } |