From 75e5b805ab6ed4ab82e75b4306045065e0620b9f Mon Sep 17 00:00:00 2001 From: Raymond Liu Date: Mon, 9 Mar 2009 14:10:45 +0800 Subject: [PATCH] [text] Insertion of multi-byte characters broken 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 --- clutter/clutter-text.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c index a9875778b..4e8e38ad9 100644 --- a/clutter/clutter-text.c +++ b/clutter/clutter-text.c @@ -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); }