From 473f7ee31ebd6d52126978ba4e155a3bebc4cac1 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 19 Oct 2009 15:31:29 +0100 Subject: [PATCH] text: Take pre-edit cursor position into account When determining the cursor position we also need to take into account the pre-edit cursor position as set by the set_preedit_string() function. --- clutter/clutter-text.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c index 5abc57d6c..92b884824 100644 --- a/clutter/clutter-text.c +++ b/clutter/clutter-text.c @@ -574,7 +574,12 @@ clutter_text_position_to_coords (ClutterText *self, if (position == -1) { if (priv->password_char == 0) - index_ = priv->n_bytes; + { + if (priv->editable && priv->preedit_set) + index_ = priv->n_bytes + strlen (priv->preedit_str); + else + index_ = priv->n_bytes; + } else index_ = n_chars * password_char_bytes; } @@ -584,10 +589,14 @@ clutter_text_position_to_coords (ClutterText *self, } else { + gchar *text = clutter_text_get_display_text (self); + if (priv->password_char == 0) - index_ = offset_to_bytes (priv->text, position); + index_ = offset_to_bytes (text, position); else index_ = position * password_char_bytes; + + g_free (text); } pango_layout_get_cursor_pos (clutter_text_get_layout (self), @@ -624,6 +633,9 @@ clutter_text_ensure_cursor_position (ClutterText *self) position = priv->position; + if (priv->editable && priv->preedit_set) + position += priv->preedit_cursor_pos; + CLUTTER_NOTE (MISC, "Cursor at %d (preedit %s at pos: %d)", position, priv->preedit_set ? "set" : "unset",