diff options
author | Peng Wu <alexepico@gmail.com> | 2018-06-06 17:17:42 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2018-06-06 17:17:42 +0800 |
commit | c2e1912687bf89c6b0d8bb9529998f775e95ea51 (patch) | |
tree | f8f4f6b7f000893807e619db45065f86bbea4ee1 /src/PYPPinyinEditor.cc | |
parent | e9cb1572f84785cada0e5434d1b992ba1298b1a4 (diff) | |
download | ibus-libpinyin-c2e1912687bf89c6b0d8bb9529998f775e95ea51.tar.gz ibus-libpinyin-c2e1912687bf89c6b0d8bb9529998f775e95ea51.tar.xz ibus-libpinyin-c2e1912687bf89c6b0d8bb9529998f775e95ea51.zip |
re-factor updatePreeditText method
Diffstat (limited to 'src/PYPPinyinEditor.cc')
-rw-r--r-- | src/PYPPinyinEditor.cc | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/PYPPinyinEditor.cc b/src/PYPPinyinEditor.cc index 14b6832..ab26b55 100644 --- a/src/PYPPinyinEditor.cc +++ b/src/PYPPinyinEditor.cc @@ -233,15 +233,16 @@ void PinyinEditor::updatePreeditText () { /* preedit text = guessed sentence + un-parsed pinyin text */ - if (G_UNLIKELY (m_text.empty ())) { + if (G_UNLIKELY (m_text.empty () || m_candidates.empty () )) { hidePreeditText (); return; } m_buffer.clear (); - char *sentence = NULL; - pinyin_get_sentence (m_instance, 0, &sentence); - if (sentence) { + + EnhancedCandidate & candidate = m_candidates[0]; + String sentence = candidate.m_display_string; + if (CANDIDATE_NBEST_MATCH == candidate.m_candidate_type) { if (m_props.modeSimp ()) { m_buffer<<sentence; } else { @@ -259,11 +260,8 @@ PinyinEditor::updatePreeditText () size_t offset = 0; guint cursor = getPinyinCursor (); - pinyin_get_character_offset(m_instance, sentence, cursor, &offset); + pinyin_get_character_offset(m_instance, sentence.c_str (), cursor, &offset); Editor::updatePreeditText (preedit_text, offset, TRUE); - - if (sentence) - g_free (sentence); } #if 0 |