unselectCandidates before move cursor left or remove char before cursor
authorPeng Huang <shawn.p.huang@gmail.com>
Sun, 4 Apr 2010 05:08:13 +0000 (13:08 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Sun, 4 Apr 2010 05:08:13 +0000 (13:08 +0800)
src/PhraseEditor.h
src/PinyinEditor.cc

index bdf2b41..088c58c 100644 (file)
@@ -34,6 +34,19 @@ public:
         return phrase.len > 1 && phrase.user_freq > 0 && phrase.freq == 0;
     }
 
+    gboolean unselectCandidates (void) {
+        if (m_cursor == 0) {
+            return FALSE;
+        }
+        else {
+            m_selected_phrases.removeAll ();
+            m_selected_string.truncate (0);
+            m_cursor = 0;
+            updateCandidates ();
+            return TRUE;
+        }
+    }
+
     void reset (void) {
         m_candidates.removeAll ();
         m_selected_phrases.removeAll ();
index 7d2866d..6cc24eb 100644 (file)
@@ -173,7 +173,12 @@ PinyinEditor::processOthers (guint keyval, guint keycode, guint modifiers)
             break;
 
         case IBUS_BackSpace:
-            removeCharBefore ();
+            if (m_phrase_editor.unselectCandidates ()) {
+                update ();
+            }
+            else {
+                removeCharBefore ();
+            }
             break;
 
         case IBUS_Delete:
@@ -183,7 +188,12 @@ PinyinEditor::processOthers (guint keyval, guint keycode, guint modifiers)
 
         case IBUS_Left:
         case IBUS_KP_Left:
-            moveCursorLeft ();
+            if (m_phrase_editor.unselectCandidates ()) {
+                update ();
+            }
+            else {
+                moveCursorLeft ();
+            }
             break;
 
         case IBUS_Right:
@@ -193,7 +203,12 @@ PinyinEditor::processOthers (guint keyval, guint keycode, guint modifiers)
 
         case IBUS_Home:
         case IBUS_KP_Home:
-            moveCursorToBegin ();
+            if (m_phrase_editor.unselectCandidates ()) {
+                update ();
+            }
+            else {
+                moveCursorToBegin ();
+            }
             break;
 
         case IBUS_End:
@@ -226,7 +241,12 @@ PinyinEditor::processOthers (guint keyval, guint keycode, guint modifiers)
     else {
         switch (keyval) {
         case IBUS_BackSpace:
-            removeWordBefore ();
+            if (m_phrase_editor.unselectCandidates ()) {
+                update ();
+            }
+            else {
+                removeWordBefore ();
+            }
             break;
 
         case IBUS_Delete:
@@ -236,7 +256,12 @@ PinyinEditor::processOthers (guint keyval, guint keycode, guint modifiers)
 
         case IBUS_Left:
         case IBUS_KP_Left:
-            moveCursorLeftByWord ();
+            if (m_phrase_editor.unselectCandidates ()) {
+                update ();
+            }
+            else {
+                moveCursorLeftByWord ();
+            }
             break;
 
         case IBUS_Right: