[text] Fix the deletion actions
authorEmmanuele Bassi <ebassi@linux.intel.com>
Tue, 6 Jan 2009 20:54:20 +0000 (20:54 +0000)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Tue, 6 Jan 2009 20:54:20 +0000 (20:54 +0000)
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

index da74de1..a493126 100644 (file)
@@ -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);