summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2014-07-17 13:22:00 +0800
committerPeng Wu <alexepico@gmail.com>2014-07-17 13:22:00 +0800
commitd55ddd91369b21c1c52a97b55417ae27b7774752 (patch)
treeb4ed661197d681e31f350cb1d70519a3598595d5
parent845b2be28e93b9abecfabeaaecc7212a61ed0b93 (diff)
downloadibus-libzhuyin-d55ddd91369b21c1c52a97b55417ae27b7774752.tar.gz
ibus-libzhuyin-d55ddd91369b21c1c52a97b55417ae27b7774752.tar.xz
ibus-libzhuyin-d55ddd91369b21c1c52a97b55417ae27b7774752.zip
fixes method moveCursorLeft
-rw-r--r--src/ZYZPhoneticEditor.cc74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/ZYZPhoneticEditor.cc b/src/ZYZPhoneticEditor.cc
index 02bc818..f988dbe 100644
--- a/src/ZYZPhoneticEditor.cc
+++ b/src/ZYZPhoneticEditor.cc
@@ -490,6 +490,80 @@ PhoneticEditor::moveCursorLeft (void)
if (G_UNLIKELY (m_cursor == 0))
return FALSE;
+ /* NOTE: adjust cursor when in parsed phonetic section. */
+
+ /* decrement the cursor variable to calculate the zhuyin cursor. */
+ guint cursor = m_cursor;
+ /* move cursor one character back. */
+ cursor --;
+
+ const String & enhanced_text = m_text;
+
+ size_t index = 0;
+ size_t start_pos = 0, end_pos = 0;
+
+ while (end_pos != enhanced_text.size ()) {
+ if (0 == cursor)
+ break;
+
+ start_pos = end_pos;
+ section_t type = probe_section_quick (enhanced_text, start_pos);
+
+ if (PHONETIC_SECTION == type) {
+ String section;
+ get_phonetic_section (enhanced_text, start_pos, end_pos, section);
+
+ size_t section_len = end_pos - start_pos;
+
+ if (cursor < section_len)
+ break;
+
+ cursor -= section_len;
+ ++index;
+ }
+
+ if (SYMBOL_SECTION == type) {
+ String type, lookup, choice;
+ get_symbol_section (enhanced_text, start_pos, end_pos,
+ type, lookup, choice);
+ --cursor;
+ }
+ }
+
+ section_t type = probe_section_quick (enhanced_text, start_pos);
+
+ /* only when in phonetic section, need adjustments. */
+ if (PHONETIC_SECTION == type) {
+ String section;
+ get_phonetic_section (enhanced_text, start_pos, end_pos, section);
+ size_t section_len = end_pos - start_pos;
+
+ zhuyin_instance_t * instance = m_instances[index];
+ size_t parsed_len = zhuyin_get_parsed_input_length (instance);
+
+ assert (cursor < section_len);
+ assert (parsed_len <= section_len);
+
+ /* only when in parsed phonetic section, need adjustments. */
+ if (cursor < parsed_len) {
+ guint16 offset = 0;
+ zhuyin_get_zhuyin_key_rest_offset (instance, cursor, &offset);
+
+ /* move to the beginning of currect syllable. */
+ ChewingKeyRest * key_rest = NULL;
+ zhuyin_get_zhuyin_key_rest (instance, offset, &key_rest);
+
+ guint16 begin = 0;
+ zhuyin_get_zhuyin_key_rest_positions
+ (instance, key_rest, &begin, NULL);
+
+ /* align to the beginning of chewing key. */
+ m_cursor = start_pos + begin;
+ update ();
+ return TRUE;
+ }
+ }
+
m_cursor --;
update ();
return TRUE;