return TRUE;
}
-gboolean
-LibPinyinFullPinyinEditor::removeWordBefore (void)
+guint
+LibPinyinFullPinyinEditor::getCursorLeftByWord (void)
{
- if (G_UNLIKELY (m_cursor == 0))
- return FALSE;
-
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
- (m_instance->m_pinyin_poses, PinyinKeyPos, pinyin_cursor);
+ (pinyin_poses, PinyinKeyPos, pinyin_cursor);
cursor = pos->m_pos;
+
/* cursor at the begin of one pinyin */
- g_return_val_if_fail (pinyin_cursor > 0, FALSE);
+ g_return_val_if_fail (pinyin_cursor > 0, 0);
if ( cursor == m_cursor) {
pos = &g_array_index
- (m_instance->m_pinyin_poses, PinyinKeyPos, pinyin_cursor - 1);
+ (pinyin_poses, PinyinKeyPos, pinyin_cursor - 1);
cursor = pos->m_pos;
}
}
- m_text.erase (cursor, m_cursor - cursor);
- m_cursor = cursor;
- updatePinyin ();
- update ();
- return TRUE;
+ return cursor;
}
-gboolean
-LibPinyinFullPinyinEditor::removeWordAfter (void)
+guint
+LibPinyinFullPinyinEditor::getCursorRightByWord (void)
{
- if (G_UNLIKELY (m_cursor == m_text.length ()))
- return FALSE;
-
guint cursor;
if (G_UNLIKELY (m_cursor > m_pinyin_len)) {
guint pinyin_cursor = getPinyinCursor ();
PinyinKeyPos *pos = &g_array_index
(m_instance->m_pinyin_poses, PinyinKeyPos, pinyin_cursor);
- cursor = pos->m_pos + pos->m_len;
+ cursor = pos->get_end_pos ();
}
+ return cursor;
+}
+
+gboolean
+LibPinyinFullPinyinEditor::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
+LibPinyinFullPinyinEditor::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 ();
if (G_UNLIKELY (m_cursor == 0))
return FALSE;
- guint cursor;
-
- if (G_UNLIKELY (m_cursor > m_pinyin_len)) {
- cursor = m_pinyin_len;
- } else {
- guint pinyin_cursor = getPinyinCursor ();
- PinyinKeyPos *pos = &g_array_index
- (m_instance->m_pinyin_poses, PinyinKeyPos, pinyin_cursor);
- cursor = pos->m_pos;
- /* cursor at the begin of one pinyin */
- g_return_val_if_fail (pinyin_cursor > 0, FALSE);
- if ( cursor == m_cursor) {
- pos = &g_array_index
- (m_instance->m_pinyin_poses, PinyinKeyPos, pinyin_cursor - 1);
- cursor = pos->m_pos;
- }
- }
+ guint cursor = getCursorLeftByWord ();
m_cursor = cursor;
update ();
if (G_UNLIKELY (m_cursor == m_text.length ()))
return FALSE;
- 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->m_pos + pos->m_len;
- }
+ guint cursor = getCursorRightByWord ();
m_cursor = cursor;
update ();