From bc51b8ca47ac90e52ab6a27ff791ea97d53f4648 Mon Sep 17 00:00:00 2001 From: Raymond Liu Date: Mon, 9 Nov 2009 16:42:15 +0800 Subject: [PATCH] Fix cursor position in preedit status http://bugzilla.openedhand.com/show_bug.cgi?id=1871 Signed-off-by: Emmanuele Bassi --- clutter/clutter-text.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c index f8432d4e8..c95a4cfce 100644 --- a/clutter/clutter-text.c +++ b/clutter/clutter-text.c @@ -590,13 +590,19 @@ clutter_text_position_to_coords (ClutterText *self, else { gchar *text = clutter_text_get_display_text (self); + GString *tmp = g_string_new (text); + gint cursor_index; + + cursor_index = offset_to_bytes (text, priv->position); + g_string_insert (tmp, cursor_index, priv->preedit_str); if (priv->password_char == 0) - index_ = offset_to_bytes (text, position); + index_ = offset_to_bytes (tmp->str, position); else index_ = position * password_char_bytes; g_free (text); + g_string_free (tmp, TRUE); } pango_layout_get_cursor_pos (clutter_text_get_layout (self), @@ -634,7 +640,11 @@ clutter_text_ensure_cursor_position (ClutterText *self) position = priv->position; if (priv->editable && priv->preedit_set) - position += priv->preedit_cursor_pos; + { + if (position == -1) + position = priv->n_chars; + position += priv->preedit_cursor_pos; + } CLUTTER_NOTE (MISC, "Cursor at %d (preedit %s at pos: %d)", position,