diff options
author | Peng Wu <alexepico@gmail.com> | 2022-10-09 13:32:26 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2022-10-09 13:32:26 +0800 |
commit | d7217bcfa7cf24dfda0ef5bc3c0c0fe000d2f806 (patch) | |
tree | 36d6ee7ecbd3fd25ac913465e1e97f58075f594f | |
parent | eb6b45f7a4cd52fdbe23e0539e5119b43f7a281a (diff) | |
download | ibus-libpinyin-d7217bcfa7cf24dfda0ef5bc3c0c0fe000d2f806.tar.gz |
Add updateAll method to class Editor
-rw-r--r-- | src/PYEditor.cc | 6 | ||||
-rw-r--r-- | src/PYEditor.h | 6 | ||||
-rw-r--r-- | src/PYEnglishEditor.cc | 16 | ||||
-rw-r--r-- | src/PYEnglishEditor.h | 3 | ||||
-rw-r--r-- | src/PYExtEditor.cc | 7 | ||||
-rw-r--r-- | src/PYExtEditor.h | 1 | ||||
-rw-r--r-- | src/PYPPhoneticEditor.cc | 7 | ||||
-rw-r--r-- | src/PYPPhoneticEditor.h | 1 | ||||
-rw-r--r-- | src/PYPPinyinEngine.cc | 37 | ||||
-rw-r--r-- | src/PYTableEditor.cc | 7 | ||||
-rw-r--r-- | src/PYTableEditor.h | 2 |
11 files changed, 87 insertions, 6 deletions
diff --git a/src/PYEditor.cc b/src/PYEditor.cc index 6c9d6b4..2b2f003 100644 --- a/src/PYEditor.cc +++ b/src/PYEditor.cc @@ -152,6 +152,12 @@ Editor::update (void) } } +void +Editor::updateAll (void) +{ + update (); +} + int Editor::selectCandidateInternal (EnhancedCandidate & candidate) { diff --git a/src/PYEditor.h b/src/PYEditor.h index 302c6c4..45bfd2e 100644 --- a/src/PYEditor.h +++ b/src/PYEditor.h @@ -63,6 +63,7 @@ public: virtual void cursorUp (void); virtual void cursorDown (void); virtual void update (void); + virtual void updateAll (void); virtual void reset (void); virtual void candidateClicked (guint index, guint button, guint state); @@ -71,6 +72,11 @@ public: return m_text; } + const guint cursor (void) const + { + return m_cursor; + } + void setText (const String & text, guint cursor) { m_text = text; diff --git a/src/PYEnglishEditor.cc b/src/PYEnglishEditor.cc index 001a20d..408d2e3 100644 --- a/src/PYEnglishEditor.cc +++ b/src/PYEnglishEditor.cc @@ -22,6 +22,7 @@ #include <string.h> #include <string> #include <stdio.h> +#include <limits> #include <libintl.h> #include "PYConfig.h" @@ -80,11 +81,19 @@ EnglishEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers) m_cursor ++; } else { g_return_val_if_fail ('v' == m_text[0] || 'V' == m_text[0], FALSE); + if ((keyval >= 'a' && keyval <= 'z') || (keyval >= 'A' && keyval <= 'Z')) { m_text.insert (m_cursor, keyval); m_cursor ++; } + + if (keyval <= std::numeric_limits<char>::max() && + g_unichar_ispunct (keyval) && + EnglishSymbols.find(keyval) != std::string::npos) { + m_text.insert (m_cursor, keyval); + m_cursor ++; + } } /* Deal other staff with updateStateFromInput (). */ @@ -345,6 +354,13 @@ EnglishEditor::update (void) } void +EnglishEditor::updateAll (void) +{ + updateStateFromInput (); + update (); +} + +void EnglishEditor::reset (void) { m_text = ""; diff --git a/src/PYEnglishEditor.h b/src/PYEnglishEditor.h index c20d465..5685d24 100644 --- a/src/PYEnglishEditor.h +++ b/src/PYEnglishEditor.h @@ -29,6 +29,8 @@ namespace PY { class EnglishDatabase; +static const std::string EnglishSymbols = "`~!@*()+[]{}\\|;':\"/<>?"; + class EnglishEditor : public Editor { private: const float m_train_factor; @@ -42,6 +44,7 @@ public: virtual void cursorUp (void); virtual void cursorDown (void); virtual void update (void); + virtual void updateAll (void); virtual void reset (void); virtual void candidateClicked (guint index, guint button, guint state); diff --git a/src/PYExtEditor.cc b/src/PYExtEditor.cc index 1e33788..4ff2173 100644 --- a/src/PYExtEditor.cc +++ b/src/PYExtEditor.cc @@ -461,6 +461,13 @@ ExtEditor::update (void) } void +ExtEditor::updateAll (void) +{ + updateStateFromInput (); + update (); +} + +void ExtEditor::reset (void) { m_text = ""; diff --git a/src/PYExtEditor.h b/src/PYExtEditor.h index 1246c1d..d9c6bce 100644 --- a/src/PYExtEditor.h +++ b/src/PYExtEditor.h @@ -34,6 +34,7 @@ public: virtual void cursorUp (void); virtual void cursorDown (void); virtual void update (void); + virtual void updateAll (void); virtual void reset (void); virtual void candidateClicked (guint index, guint button, guint state); diff --git a/src/PYPPhoneticEditor.cc b/src/PYPPhoneticEditor.cc index ee0b8ce..9aacb43 100644 --- a/src/PYPPhoneticEditor.cc +++ b/src/PYPPhoneticEditor.cc @@ -356,6 +356,13 @@ PhoneticEditor::update (void) updateAuxiliaryText (); } +void +PhoneticEditor::updateAll (void) +{ + updatePinyin (); + update (); +} + guint PhoneticEditor::getPinyinCursor () { diff --git a/src/PYPPhoneticEditor.h b/src/PYPPhoneticEditor.h index 2a16d87..03e61aa 100644 --- a/src/PYPPhoneticEditor.h +++ b/src/PYPPhoneticEditor.h @@ -64,6 +64,7 @@ public: virtual void cursorUp (void); virtual void cursorDown (void); virtual void update (void); + virtual void updateAll (void); virtual void reset (void); virtual void candidateClicked (guint index, guint button, guint state); virtual gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); diff --git a/src/PYPPinyinEngine.cc b/src/PYPPinyinEngine.cc index 786f2f3..5e13b56 100644 --- a/src/PYPPinyinEngine.cc +++ b/src/PYPPinyinEngine.cc @@ -21,6 +21,7 @@ #include "PYPPinyinEngine.h" #include <string> #include <assert.h> +#include <limits> #include "PYConfig.h" #include "PYPConfig.h" #include "PYPunctEditor.h" @@ -364,6 +365,33 @@ PinyinEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers) #endif } else { +#ifdef IBUS_BUILD_ENGLISH_INPUT_MODE + // for english mode switch with symbol key + if (keyval <= std::numeric_limits<char>::max() && + g_unichar_ispunct (keyval) && + EnglishSymbols.find(keyval) != std::string::npos && + m_input_mode == MODE_INIT && + PinyinConfig::instance ().englishInputMode ()) { + String text; + if (!PinyinConfig::instance ().doublePinyin ()) + text = "v"; // full pinyin + else + text = "V"; // double pinyin + text += m_editors[m_input_mode]->text (); + guint cursor = m_editors[m_input_mode]->cursor () + 1; + + /* insert the new symbol char here. */ + text.insert(cursor, keyval); + cursor += 1; + + m_editors[m_input_mode]->setText ("", 0); + m_input_mode = MODE_ENGLISH; + m_editors[m_input_mode]->setText (text, cursor); + Editor * editor = m_editors[m_input_mode].get (); + m_editors[m_input_mode]->updateAll (); + return TRUE; + } +#endif #ifdef IBUS_BUILD_TABLE_INPUT_MODE // for table mode switch with tab key if (keyval == IBUS_Tab && @@ -375,14 +403,13 @@ PinyinEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers) else text = "U"; // double pinyin text += m_editors[m_input_mode]->text (); - m_editors[m_input_mode]->setText ("", 0); + guint cursor = m_editors[m_input_mode]->cursor () + 1; + m_editors[m_input_mode]->setText ("", 0); m_input_mode = MODE_TABLE; - m_editors[m_input_mode]->setText (text, text.length ()); + m_editors[m_input_mode]->setText (text, cursor); Editor * editor = m_editors[m_input_mode].get (); - /* Note: consider to remove the updateStateFromInput method call here. */ - dynamic_cast<TableEditor *>(editor)->updateStateFromInput (); - m_editors[m_input_mode]->update (); + m_editors[m_input_mode]->updateAll (); return TRUE; } #endif diff --git a/src/PYTableEditor.cc b/src/PYTableEditor.cc index 2b62101..1e46154 100644 --- a/src/PYTableEditor.cc +++ b/src/PYTableEditor.cc @@ -365,6 +365,13 @@ TableEditor::update (void) } void +TableEditor::updateAll (void) +{ + updateStateFromInput (); + update (); +} + +void TableEditor::reset (void) { m_text = ""; diff --git a/src/PYTableEditor.h b/src/PYTableEditor.h index 8e29bc5..cc778cf 100644 --- a/src/PYTableEditor.h +++ b/src/PYTableEditor.h @@ -31,7 +31,6 @@ namespace PY { class PinyinEngine; class TableEditor : public Editor { - friend class PinyinEngine; public: TableEditor (PinyinProperties &props, Config & config); virtual ~TableEditor (); @@ -42,6 +41,7 @@ public: virtual void cursorUp (void); virtual void cursorDown (void); virtual void update (void); + virtual void updateAll (void); virtual void reset (void); virtual void candidateClicked (guint index, guint button, guint state); |