From 8182b354b167681a89ef9c3354c1278378e4ea2c Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 6 Jan 2009 20:54:20 +0000 Subject: [PATCH] [text] Fix the deletion actions When using the delete-prev action from the end of the text we end up either missing the first glyph we have to delete or falling through the last one in the text. This commit fixes both issues. --- clutter/clutter-text.c | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c index da74de1..a493126 100644 --- a/clutter/clutter-text.c +++ b/clutter/clutter-text.c @@ -1388,16 +1388,12 @@ clutter_text_real_del_next (ClutterText *self, return TRUE; pos = priv->position; - len = g_utf8_strlen (priv->text, -1); + len = priv->n_chars; if (len && pos != -1 && pos < len) - { - clutter_text_delete_text (self, pos, pos + 1); - - return TRUE; - } + clutter_text_delete_text (self, pos, pos + 1); - return FALSE; + return TRUE; } static gboolean @@ -1414,7 +1410,7 @@ clutter_text_real_del_prev (ClutterText *self, return TRUE; pos = priv->position; - len = g_utf8_strlen (priv->text, -1); + len = priv->n_chars; if (pos != 0 && len != 0) { @@ -1422,19 +1418,19 @@ clutter_text_real_del_prev (ClutterText *self, { clutter_text_set_cursor_position (self, len - 1); clutter_text_set_selection_bound (self, len - 1); + + clutter_text_delete_text (self, len - 1, len); } else { clutter_text_set_cursor_position (self, pos - 1); clutter_text_set_selection_bound (self, pos - 1); - } - - clutter_text_delete_text (self, pos - 1, pos); - return TRUE; + clutter_text_delete_text (self, pos - 1, pos); + } } - return FALSE; + return TRUE; } static gboolean @@ -3480,18 +3476,15 @@ clutter_text_delete_text (ClutterText *self, if (!priv->text) return; + if (start_pos == 0) + start_bytes = 0; + else + start_bytes = offset_to_bytes (priv->text, start_pos); + if (end_pos == -1) - { - start_bytes = offset_to_bytes (priv->text, - g_utf8_strlen (priv->text, -1) - 1); - end_bytes = offset_to_bytes (priv->text, - g_utf8_strlen (priv->text, -1)); - } + end_bytes = offset_to_bytes (priv->text, priv->n_chars); else - { - start_bytes = offset_to_bytes (priv->text, start_pos); - end_bytes = offset_to_bytes (priv->text, end_pos); - } + end_bytes = offset_to_bytes (priv->text, end_pos); new = g_string_new (priv->text); new = g_string_erase (new, start_bytes, end_bytes - start_bytes); -- 2.7.4