From e470a4fffcc4d3ea1a0b85347ab284dde4738ad7 Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Sun, 4 Apr 2010 13:08:13 +0800 Subject: [PATCH] unselectCandidates before move cursor left or remove char before cursor --- src/PhraseEditor.h | 13 +++++++++++++ src/PinyinEditor.cc | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/PhraseEditor.h b/src/PhraseEditor.h index bdf2b41..088c58c 100644 --- a/src/PhraseEditor.h +++ b/src/PhraseEditor.h @@ -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 (); diff --git a/src/PinyinEditor.cc b/src/PinyinEditor.cc index 7d2866d..6cc24eb 100644 --- a/src/PinyinEditor.cc +++ b/src/PinyinEditor.cc @@ -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: -- 2.7.4