summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2018-06-06 17:17:42 +0800
committerPeng Wu <alexepico@gmail.com>2018-06-06 17:17:42 +0800
commitc2e1912687bf89c6b0d8bb9529998f775e95ea51 (patch)
treef8f4f6b7f000893807e619db45065f86bbea4ee1 /src
parente9cb1572f84785cada0e5434d1b992ba1298b1a4 (diff)
downloadibus-libpinyin-c2e1912687bf89c6b0d8bb9529998f775e95ea51.tar.gz
ibus-libpinyin-c2e1912687bf89c6b0d8bb9529998f775e95ea51.tar.xz
ibus-libpinyin-c2e1912687bf89c6b0d8bb9529998f775e95ea51.zip
re-factor updatePreeditText method
Diffstat (limited to 'src')
-rw-r--r--src/PYLibPinyin.cc4
-rw-r--r--src/PYPBopomofoEditor.cc34
-rw-r--r--src/PYPPinyinEditor.cc14
3 files changed, 31 insertions, 21 deletions
diff --git a/src/PYLibPinyin.cc b/src/PYLibPinyin.cc
index 1f94ba6..34e2424 100644
--- a/src/PYLibPinyin.cc
+++ b/src/PYLibPinyin.cc
@@ -309,8 +309,8 @@ LibPinyinBackEnd::clearPinyinUserData (const char *target)
}
gboolean
-LibPinyinBackEnd::rememberUserInput (pinyin_instance_t * instance,
- const gchar * phrase)
+LibPinyinBackEnd::rememberUserInput (pinyin_instance_t *instance,
+ const gchar *phrase)
{
/* pre-check the incomplete pinyin keys, prepare pinyin string,
remember user input. */
diff --git a/src/PYPBopomofoEditor.cc b/src/PYPBopomofoEditor.cc
index 688fb5f..452372f 100644
--- a/src/PYPBopomofoEditor.cc
+++ b/src/PYPBopomofoEditor.cc
@@ -344,15 +344,16 @@ void
BopomofoEditor::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 {
@@ -360,9 +361,23 @@ BopomofoEditor::updatePreeditText ()
}
}
- /* append rest text */
- const gchar *p = m_text.c_str () + m_pinyin_len;
- m_buffer << p;
+ /* text after pinyin */
+ const gchar *p = m_text.c_str() + m_pinyin_len;
+ while (*p != '\0') {
+ gchar ** symbols = NULL;
+ if (pinyin_in_chewing_keyboard (m_instance, *p, &symbols)) {
+ g_assert (1 == g_strv_length (symbols));
+ m_buffer << symbols[0];
+ g_strfreev (symbols);
+ } else {
+ if (G_UNLIKELY (m_props.modeFull ())) {
+ m_buffer.appendUnichar (HalfFullConverter::toFull (*p));
+ } else {
+ m_buffer << *p;
+ }
+ }
+ ++p;
+ }
StaticText preedit_text (m_buffer);
/* underline */
@@ -370,11 +385,8 @@ BopomofoEditor::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);
}
void
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