summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2018-06-15 16:02:00 +0800
committerPeng Wu <alexepico@gmail.com>2018-06-15 16:02:00 +0800
commit6eed8c257e9c5870fcd32aa8eedf01ce7bec6613 (patch)
tree66728b86a14420b0b439f701523dc10f672066c9
parent43f0846c494b5bf1b759905ee1d2dc2c2de02059 (diff)
downloadibus-libpinyin-6eed8c257e9c5870fcd32aa8eedf01ce7bec6613.tar.gz
ibus-libpinyin-6eed8c257e9c5870fcd32aa8eedf01ce7bec6613.tar.xz
ibus-libpinyin-6eed8c257e9c5870fcd32aa8eedf01ce7bec6613.zip
support suggestion mode in PinyinEngine
-rw-r--r--src/PYPPinyinEngine.cc33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/PYPPinyinEngine.cc b/src/PYPPinyinEngine.cc
index 324ebe3..cee9681 100644
--- a/src/PYPPinyinEngine.cc
+++ b/src/PYPPinyinEngine.cc
@@ -21,6 +21,7 @@
*/
#include "PYPPinyinEngine.h"
#include <string>
+#include <assert.h>
#include "PYConfig.h"
#include "PYPConfig.h"
#include "PYPunctEditor.h"
@@ -184,6 +185,24 @@ PinyinEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers)
/* return from MODE_SUGGESTION to normal input. */
if (m_input_mode == MODE_SUGGESTION) {
/* only accept input to select candidate. */
+ if (IBUS_Escape == keyval) {
+ m_editors[m_input_mode]->reset ();
+ m_input_mode = MODE_INIT;
+ /* m_editors[m_input_mode]->reset (); */
+ m_editors[m_input_mode]->update ();
+ return TRUE;
+ }
+
+ switch (keyval) {
+ case IBUS_0 ... IBUS_9:
+ case IBUS_space:
+ case IBUS_Return:
+ /* still in suggestion mode. */
+ break;
+
+ default:
+ m_input_mode = MODE_INIT;
+ }
}
/* handle normal input. */
@@ -366,8 +385,20 @@ void
PinyinEngine::commitText (Text & text)
{
Engine::commitText (text);
- if (m_input_mode != MODE_INIT)
+
+ if (m_input_mode != MODE_INIT && m_input_mode != MODE_SUGGESTION)
m_input_mode = MODE_INIT;
+ else if (PinyinConfig::instance ().showSuggestion ()) {
+ if (m_input_mode == MODE_INIT) {
+ m_input_mode = MODE_SUGGESTION;
+ m_editors[m_input_mode]->setText (text.text (), 0);
+ m_editors[m_input_mode]->update ();
+ } else if (m_input_mode == MODE_SUGGESTION) {
+ m_editors[m_input_mode]->setText (text.text (), 0);
+ m_editors[m_input_mode]->update ();
+ } else
+ assert (FALSE);
+ }
#if 1
/* handle "<num>+.<num>+" here */
if (text.text ())