Show auxiliary text correctly with special phrase.
authorPeng Huang <shawn.p.huang@gmail.com>
Tue, 13 Apr 2010 14:17:43 +0000 (22:17 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Tue, 13 Apr 2010 14:17:43 +0000 (22:17 +0800)
src/PinyinEditor.cc
src/PinyinEditor.h

index f018704..1e5c1a4 100644 (file)
@@ -416,26 +416,33 @@ PinyinEditor::updateAuxiliaryText (void)
     updateAuxiliaryTextBefore (m_buffer);
 
     if (m_selected_special_phrase.empty ()) {
-        for (guint i = m_phrase_editor.cursor (); i < m_pinyin.size (); ++i) {
-            if (G_LIKELY (i != m_phrase_editor.cursor ()))
-                m_buffer << ' ';
-            const Pinyin *p = m_pinyin[i];
-            m_buffer << p->sheng
-                     << p->yun;
-        }
-
-        if (G_UNLIKELY (m_pinyin_len == m_cursor)) {
-            /* aux = pinyin + non-pinyin */
-            // cursor_pos =  m_buffer.utf8Length ();
-            m_buffer << '|' << textAfterPinyin ();
+        if (m_lookup_table.cursorPos () < m_special_phrases.size ()) {
+            guint begin = m_phrase_editor.cursorInChar ();
+            m_buffer << m_text.substr (begin, m_cursor - begin)
+                     << '|' << textAfterCursor ();
         }
         else {
-            /* aux = pinyin + ' ' + non-pinyin before cursor + non-pinyin after cursor */
-            m_buffer << ' ';
-            m_buffer.append (textAfterPinyin (),
-                         m_cursor - m_pinyin_len);
-            // cursor_pos =  m_buffer.utf8Length ();
-            m_buffer  << '|' << textAfterCursor ();
+            for (guint i = m_phrase_editor.cursor (); i < m_pinyin.size (); ++i) {
+                if (G_LIKELY (i != m_phrase_editor.cursor ()))
+                    m_buffer << ' ';
+                const Pinyin *p = m_pinyin[i];
+                m_buffer << p->sheng
+                         << p->yun;
+            }
+
+            if (G_UNLIKELY (m_pinyin_len == m_cursor)) {
+                /* aux = pinyin + non-pinyin */
+                // cursor_pos =  m_buffer.utf8Length ();
+                m_buffer << '|' << textAfterPinyin ();
+            }
+            else {
+                /* aux = pinyin + ' ' + non-pinyin before cursor + non-pinyin after cursor */
+                m_buffer << ' ';
+                m_buffer.append (textAfterPinyin (),
+                             m_cursor - m_pinyin_len);
+                // cursor_pos =  m_buffer.utf8Length ();
+                m_buffer  << '|' << textAfterCursor ();
+            }
         }
     }
     else {
@@ -524,6 +531,7 @@ PinyinEditor::pageUp (void)
     if (G_LIKELY (m_lookup_table.pageUp ())) {
         updateLookupTableFast (m_lookup_table, TRUE);
         updatePreeditText ();
+        updateAuxiliaryText ();
     }
 }
 
@@ -535,6 +543,7 @@ PinyinEditor::pageDown (void)
             (fillLookupTableByPage () && m_lookup_table.pageDown ()))) {
         updateLookupTableFast (m_lookup_table, TRUE);
         updatePreeditText ();
+        updateAuxiliaryText ();
     }
 }
 
@@ -544,6 +553,7 @@ PinyinEditor::cursorUp (void)
     if (G_LIKELY (m_lookup_table.cursorUp ())) {
         updateLookupTableFast (m_lookup_table, TRUE);
         updatePreeditText ();
+        updateAuxiliaryText ();
     }
 }
 
@@ -559,6 +569,7 @@ PinyinEditor::cursorDown (void)
     if (G_LIKELY (m_lookup_table.cursorDown ())) {
         updateLookupTableFast (m_lookup_table, TRUE);
         updatePreeditText ();
+        updateAuxiliaryText ();
     }
 }
 
@@ -599,12 +610,6 @@ PinyinEditor::update (void)
     updateAuxiliaryText ();
 }
 
-void
-PinyinEditor::updatePhraseEditor (void)
-{
-    m_phrase_editor.update (m_pinyin);
-}
-
 inline void
 PinyinEditor::commit (const gchar *str)
 {
index 76bfe12..aaa2f8a 100644 (file)
@@ -44,7 +44,25 @@ protected:
     void updateLookupTable (void);
     gboolean fillLookupTableByPage (void);
 
-    void updatePhraseEditor (void);
+    void updatePhraseEditor (void) { m_phrase_editor.update (m_pinyin); }
+
+    gboolean updateSpecialPhrases (void) {
+        if (!m_selected_special_phrase.empty ())
+            return FALSE;
+
+        guint size = m_special_phrases.size ();
+        guint begin = m_phrase_editor.cursorInChar ();
+        guint end = m_cursor;
+
+        m_special_phrases.clear ();
+        if (begin < end) {
+            SpecialTable::instance ().lookup (
+                m_text.substr (begin, m_cursor - begin),
+                m_special_phrases);
+        }
+
+        return size != m_special_phrases.size () || size != 0;
+    }
 
     gboolean selectCandidate (guint i);
     gboolean selectCandidateInPage (guint i);
@@ -70,20 +88,6 @@ protected:
     guint pinyinLength (void) const { return m_pinyin_len; }
     operator gboolean (void) const { return ! empty (); }
 
-    gboolean updateSpecialPhrases (void) {
-        guint oldsize = m_special_phrases.size ();
-        m_special_phrases.clear ();
-        guint begin = m_phrase_editor.cursorInChar ();
-        guint end = m_cursor;
-
-        if (begin < end &&
-            m_selected_special_phrase.empty () &&
-            SpecialTable::instance ().lookup (m_text.substr (begin, m_cursor - begin), m_special_phrases)) {
-            return TRUE;
-        }
-        return oldsize > 0;
-    }
-
     /* virtual functions */
     virtual gboolean insert (gint ch) = 0;
     virtual gboolean removeCharBefore (void) = 0;