From 4300168afda16a42df805cdff8a0c5c192356283 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Sun, 21 Jun 2015 09:59:43 +0800 Subject: auto commit when press space key --- src/ZYZPhoneticEditor.h | 3 ++- src/ZYZPinyinEditor.cc | 21 ++++++++++++++++++--- src/ZYZPinyinEditor.h | 2 +- src/ZYZZhuyinEditor.cc | 21 ++++++++++++++++++--- src/ZYZZhuyinEditor.h | 2 +- 5 files changed, 40 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/ZYZPhoneticEditor.h b/src/ZYZPhoneticEditor.h index ae82615..6ba04fc 100644 --- a/src/ZYZPhoneticEditor.h +++ b/src/ZYZPhoneticEditor.h @@ -97,7 +97,8 @@ protected: virtual void commit (void) = 0; virtual void updateAuxiliaryText (void) = 0; virtual void updatePreeditText (void) = 0; - virtual void updateZhuyin (void) = 0; + /* return the last position of zhuyin symbols. */ + virtual guint updateZhuyin (void) = 0; /* for class DaChen26Editor to override this. */ virtual guint getZhuyinCursor (void); diff --git a/src/ZYZPinyinEditor.cc b/src/ZYZPinyinEditor.cc index a3683a8..30457f1 100644 --- a/src/ZYZPinyinEditor.cc +++ b/src/ZYZPinyinEditor.cc @@ -63,10 +63,12 @@ PinyinEditor::commit (void) void PinyinEditor::reset (void) { + m_preedit_text = ""; + PhoneticEditor::reset (); } -void +guint PinyinEditor::updateZhuyin (void) { const String & enhanced_text = m_text; @@ -75,6 +77,7 @@ PinyinEditor::updateZhuyin (void) size_t index = 0; size_t start_pos = 0, end_pos = 0; + guint pos = 0; while (end_pos != enhanced_text.size ()) { section_t type = probe_section_quick (enhanced_text, start_pos); @@ -84,9 +87,12 @@ PinyinEditor::updateZhuyin (void) get_phonetic_section (enhanced_text, start_pos, end_pos, section); zhuyin_instance_t * instance = m_instances[index]; - zhuyin_parse_more_full_pinyins (instance, section.c_str ()); + size_t len = zhuyin_parse_more_full_pinyins + (instance, section.c_str ()); zhuyin_guess_sentence (instance); + pos = start_pos + len; + ++index; } @@ -100,7 +106,7 @@ PinyinEditor::updateZhuyin (void) start_pos = end_pos; } - return; + return pos; } void @@ -181,6 +187,15 @@ PinyinEditor::insert (guint keyval, guint keycode, guint modifiers) if (modifiers != 0 && m_text.empty ()) return FALSE; + /* the space key is not part of pinyin string. */ + if (IBUS_space == keyval && + m_cursor == get_enhanced_text_length (m_text)) { + commit (); + StaticText space (" "); + commitText (space); + return TRUE; + } + if (IS_PINYIN (keyval)) { insert_phonetic (m_text, m_cursor++, keyval); diff --git a/src/ZYZPinyinEditor.h b/src/ZYZPinyinEditor.h index 0693947..cee3735 100644 --- a/src/ZYZPinyinEditor.h +++ b/src/ZYZPinyinEditor.h @@ -40,7 +40,7 @@ protected: virtual void updatePreeditText (); virtual void updateAuxiliaryText (); - virtual void updateZhuyin (void); + virtual guint updateZhuyin (void); void commit (); void reset (); diff --git a/src/ZYZZhuyinEditor.cc b/src/ZYZZhuyinEditor.cc index 26fc028..d377afe 100644 --- a/src/ZYZZhuyinEditor.cc +++ b/src/ZYZZhuyinEditor.cc @@ -62,10 +62,12 @@ ZhuyinEditor::commit (void) void ZhuyinEditor::reset (void) { + m_preedit_text = ""; + PhoneticEditor::reset (); } -void +guint ZhuyinEditor::updateZhuyin (void) { const String & enhanced_text = m_text; @@ -74,6 +76,7 @@ ZhuyinEditor::updateZhuyin (void) size_t index = 0; size_t start_pos = 0, end_pos = 0; + guint pos = 0; while (end_pos != enhanced_text.size ()) { section_t type = probe_section_quick (enhanced_text, start_pos); @@ -87,6 +90,8 @@ ZhuyinEditor::updateZhuyin (void) (instance, section.c_str ()); zhuyin_guess_sentence (instance); + pos = start_pos + len; + ++index; } @@ -99,7 +104,7 @@ ZhuyinEditor::updateZhuyin (void) start_pos = end_pos; } - return; + return pos; } void @@ -194,7 +199,17 @@ ZhuyinEditor::insert (guint keyval, guint keycode, guint modifiers) insert_phonetic (m_text, m_cursor++, keyval); - updateZhuyin (); + guint len = updateZhuyin (); + + /* the space key is part of zhuyin string. */ + if (IBUS_space == keyval && + len < m_text.size () && + m_cursor == get_enhanced_text_length (m_text)) { + update (); + commit (); + return TRUE; + } + update (); return TRUE; } diff --git a/src/ZYZZhuyinEditor.h b/src/ZYZZhuyinEditor.h index 40920d2..246c77b 100644 --- a/src/ZYZZhuyinEditor.h +++ b/src/ZYZZhuyinEditor.h @@ -40,7 +40,7 @@ protected: virtual void updatePreeditText (); virtual void updateAuxiliaryText (); - virtual void updateZhuyin (void); + virtual guint updateZhuyin (void); void commit (); void reset (); -- cgit