[text] Insertion of multi-byte characters broken
authorRaymond Liu <raymond.liu@intel.com>
Mon, 9 Mar 2009 06:10:45 +0000 (14:10 +0800)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Wed, 11 Mar 2009 18:00:21 +0000 (18:00 +0000)
Bug 1501 - clutter_text_insert_text not working right with non-onebyte
           character

In clutter_text_insert_text(), the position is expressed in characters, not
in bytes.

Actually, it turns out to be working on bytes, so when there are already
multi-byte character in the text buffer, insert text at the position after
the multi-byte character will not work right.

Also, the position is not updated after the insert work is done.

Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
clutter/clutter-text.c

index a987577..4e8e38a 100644 (file)
@@ -3692,17 +3692,26 @@ clutter_text_insert_text (ClutterText *self,
 {
   ClutterTextPrivate *priv;
   GString *new = NULL;
+  gint pos_bytes;
 
   g_return_if_fail (CLUTTER_IS_TEXT (self));
   g_return_if_fail (text != NULL);
 
   priv = self->priv;
 
+  pos_bytes = offset_to_bytes (priv->text, position);
+
   new = g_string_new (priv->text);
-  new = g_string_insert (new, position, text);
+  new = g_string_insert (new, pos_bytes, text);
 
   clutter_text_set_text (self, new->str);
 
+  if (position >= 0 && priv->position >= position)
+    {
+      clutter_text_set_cursor_position (self, priv->position + g_utf8_strlen (text, -1));
+      clutter_text_set_selection_bound (self, priv->position);
+    }
+
   g_string_free (new, TRUE);
 }