diff options
author | Peng Wu <alexepico@gmail.com> | 2011-11-07 13:33:28 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2011-12-22 12:23:14 +0800 |
commit | b068207b550f53309f5950ee14a2124224c36841 (patch) | |
tree | 9b5c3ce745570d8171ed3432ed108a70a56b1f20 /src/PYPPhoneticEditor.cc | |
parent | 9ea1f7abfe470fd0b2f4832eee612e98d62072b4 (diff) | |
download | ibus-libpinyin-b068207b550f53309f5950ee14a2124224c36841.tar.gz ibus-libpinyin-b068207b550f53309f5950ee14a2124224c36841.tar.xz ibus-libpinyin-b068207b550f53309f5950ee14a2124224c36841.zip |
copy move cursor by word functions
Diffstat (limited to 'src/PYPPhoneticEditor.cc')
-rw-r--r-- | src/PYPPhoneticEditor.cc | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/PYPPhoneticEditor.cc b/src/PYPPhoneticEditor.cc index dc66689..ac94ba7 100644 --- a/src/PYPPhoneticEditor.cc +++ b/src/PYPPhoneticEditor.cc @@ -418,3 +418,102 @@ LibPinyinPhoneticEditor::moveCursorToEnd (void) update (); return TRUE; } + + +/* move cursor by word functions */ + +guint +LibPinyinPhoneticEditor::getCursorLeftByWord (void) +{ + guint cursor; + + if (G_UNLIKELY (m_cursor > m_pinyin_len)) { + cursor = m_pinyin_len; + } else { + PinyinKeyPosVector & pinyin_poses = m_instance->m_pinyin_poses; + guint pinyin_cursor = getPinyinCursor (); + PinyinKeyPos *pos = &g_array_index + (pinyin_poses, PinyinKeyPos, pinyin_cursor); + cursor = pos->m_pos; + + /* cursor at the begin of one pinyin */ + g_return_val_if_fail (pinyin_cursor > 0, 0); + if ( cursor == m_cursor) { + pos = &g_array_index + (pinyin_poses, PinyinKeyPos, pinyin_cursor - 1); + cursor = pos->m_pos; + } + } + + return cursor; +} + +guint +LibPinyinPhoneticEditor::getCursorRightByWord (void) +{ + guint cursor; + + if (G_UNLIKELY (m_cursor > m_pinyin_len)) { + cursor = m_text.length (); + } else { + guint pinyin_cursor = getPinyinCursor (); + PinyinKeyPos *pos = &g_array_index + (m_instance->m_pinyin_poses, PinyinKeyPos, pinyin_cursor); + cursor = pos->get_end_pos (); + } + + return cursor; +} + +gboolean +LibPinyinPhoneticEditor::removeWordBefore (void) +{ + if (G_UNLIKELY (m_cursor == 0)) + return FALSE; + + guint cursor = getCursorLeftByWord (); + m_text.erase (cursor, m_cursor - cursor); + m_cursor = cursor; + updatePinyin (); + update (); + return TRUE; +} + +gboolean +LibPinyinPhoneticEditor::removeWordAfter (void) +{ + if (G_UNLIKELY (m_cursor == m_text.length ())) + return FALSE; + + guint cursor = getCursorRightByWord (); + m_text.erase (m_cursor, cursor - m_cursor); + updatePinyin (); + update (); + return TRUE; +} + +gboolean +LibPinyinPhoneticEditor::moveCursorLeftByWord (void) +{ + if (G_UNLIKELY (m_cursor == 0)) + return FALSE; + + guint cursor = getCursorLeftByWord (); + + m_cursor = cursor; + update (); + return TRUE; +} + +gboolean +LibPinyinPhoneticEditor::moveCursorRightByWord (void) +{ + if (G_UNLIKELY (m_cursor == m_text.length ())) + return FALSE; + + guint cursor = getCursorRightByWord (); + + m_cursor = cursor; + update (); + return TRUE; +} |