summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2015-02-11 14:11:08 +0800
committerPeng Wu <alexepico@gmail.com>2015-02-11 14:11:08 +0800
commita0d1d16d3fac134f03d40ffe802930412f0d8612 (patch)
treef42927e61b25d3f868b0f873b576f4024e58f59a
parentc4da2ab7369610b88d803d4620d823474a428879 (diff)
downloadibus-libzhuyin-a0d1d16d3fac134f03d40ffe802930412f0d8612.tar.gz
ibus-libzhuyin-a0d1d16d3fac134f03d40ffe802930412f0d8612.tar.xz
ibus-libzhuyin-a0d1d16d3fac134f03d40ffe802930412f0d8612.zip
fixes removeCharBefore and removeCharAfter methods
-rw-r--r--src/ZYZPhoneticEditor.cc117
-rw-r--r--src/ZYZPhoneticEditor.h2
2 files changed, 65 insertions, 54 deletions
diff --git a/src/ZYZPhoneticEditor.cc b/src/ZYZPhoneticEditor.cc
index 4f036d8..0a2a9e4 100644
--- a/src/ZYZPhoneticEditor.cc
+++ b/src/ZYZPhoneticEditor.cc
@@ -577,42 +577,9 @@ PhoneticEditor::selectCandidateInPage (guint index)
return selectCandidate (index);
}
-gboolean
-PhoneticEditor::removeCharBefore (void)
-{
- if (G_UNLIKELY (m_cursor == 0))
- return FALSE;
-
- m_cursor --;
- erase_input_sequence (m_text, m_cursor, 1);
-
- updateZhuyin ();
- update ();
-
- return TRUE;
-}
-
-gboolean
-PhoneticEditor::removeCharAfter (void)
-{
- if (G_UNLIKELY (m_cursor ==
- get_enhanced_text_length (m_text)))
- return FALSE;
-
- erase_input_sequence (m_text, m_cursor, 1);
-
- updateZhuyin ();
- update ();
-
- return TRUE;
-}
-
-gboolean
-PhoneticEditor::moveCursorLeft (void)
+guint
+PhoneticEditor::getCursorLeft (void)
{
- if (G_UNLIKELY (m_cursor == 0))
- return FALSE;
-
/* NOTE: adjust cursor when in parsed phonetic section. */
const String & enhanced_text = m_text;
guint cursor = m_cursor;
@@ -653,24 +620,16 @@ PhoneticEditor::moveCursorLeft (void)
/* align to the begin of chewing key. */
/* restore cursor variable. */
- m_cursor = m_cursor - (cursor + 1 - begin);
- update ();
- return TRUE;
+ return m_cursor - (cursor + 1 - begin);
}
}
- m_cursor --;
- update ();
- return TRUE;
+ return m_cursor - 1;
}
-gboolean
-PhoneticEditor::moveCursorRight (void)
+guint
+PhoneticEditor::getCursorRight (void)
{
- if (G_UNLIKELY (m_cursor ==
- get_enhanced_text_length (m_text)))
- return FALSE;
-
/* NOTE: adjust cursor when in parsed phonetic section. */
const String & enhanced_text = m_text;
guint cursor = m_cursor;
@@ -714,20 +673,70 @@ PhoneticEditor::moveCursorRight (void)
(instance, key_rest, &begin, NULL);
/* align to the begin of chewing key. */
- m_cursor = m_cursor + (begin - cursor);
- update ();
- return TRUE;
+ return m_cursor + (begin - cursor);
} else {
assert (offset == len);
/* align to the end of parsed phonetic section. */
- m_cursor = m_cursor + (parsed_len - cursor);
- update ();
- return TRUE;
+ return m_cursor + (parsed_len - cursor);
}
}
}
- m_cursor ++;
+ return m_cursor + 1;
+}
+
+
+gboolean
+PhoneticEditor::removeCharBefore (void)
+{
+ if (G_UNLIKELY (m_cursor == 0))
+ return FALSE;
+
+ guint cursor = getCursorLeft ();
+ erase_input_sequence (m_text, cursor, m_cursor - cursor);
+ m_cursor = cursor;
+
+ updateZhuyin ();
+ update ();
+
+ return TRUE;
+}
+
+gboolean
+PhoneticEditor::removeCharAfter (void)
+{
+ if (G_UNLIKELY (m_cursor ==
+ get_enhanced_text_length (m_text)))
+ return FALSE;
+
+ guint cursor = getCursorRight ();
+ erase_input_sequence (m_text, m_cursor, cursor - m_cursor);
+
+ updateZhuyin ();
+ update ();
+
+ return TRUE;
+}
+
+gboolean
+PhoneticEditor::moveCursorLeft (void)
+{
+ if (G_UNLIKELY (m_cursor == 0))
+ return FALSE;
+
+ m_cursor = getCursorLeft ();
+ update ();
+ return TRUE;
+}
+
+gboolean
+PhoneticEditor::moveCursorRight (void)
+{
+ if (G_UNLIKELY (m_cursor ==
+ get_enhanced_text_length (m_text)))
+ return FALSE;
+
+ m_cursor = getCursorRight ();
update ();
return TRUE;
}
diff --git a/src/ZYZPhoneticEditor.h b/src/ZYZPhoneticEditor.h
index 6af152d..6c6b2a0 100644
--- a/src/ZYZPhoneticEditor.h
+++ b/src/ZYZPhoneticEditor.h
@@ -78,6 +78,8 @@ protected:
gboolean prepareCandidates (void);
gboolean selectCandidate (guint i);
gboolean selectCandidateInPage (guint i);
+ guint getCursorLeft (void);
+ guint getCursorRight (void);
void commit (const gchar *str);