From 06ae4e4984c1fea0ef0154ac94e8ebba2af7140a Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Tue, 13 Apr 2010 22:17:43 +0800 Subject: [PATCH] Show auxiliary text correctly with special phrase. --- src/PinyinEditor.cc | 53 +++++++++++++++++++++++++++++------------------------ src/PinyinEditor.h | 34 +++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 39 deletions(-) diff --git a/src/PinyinEditor.cc b/src/PinyinEditor.cc index f018704..1e5c1a4 100644 --- a/src/PinyinEditor.cc +++ b/src/PinyinEditor.cc @@ -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) { diff --git a/src/PinyinEditor.h b/src/PinyinEditor.h index 76bfe12..aaa2f8a 100644 --- a/src/PinyinEditor.h +++ b/src/PinyinEditor.h @@ -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; -- 2.7.4