From 798f4ef321c980a22220cce49a0d744ee85172b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Pi=C3=B1eiro?= Date: Thu, 16 Jan 2014 18:04:22 +0100 Subject: clutter-text: emitting ClutterText::insert-text before actual changes on the text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://bugzilla.gnome.org/show_bug.cgi?id=722220 (cherry picked from commit cadbeceff0a729cdeafd84db237ed44ad782e820) Signed-off-by: Alejandro PiƱeiro --- clutter/clutter-text.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c index abc56088b..a74973916 100644 --- a/clutter/clutter-text.c +++ b/clutter/clutter-text.c @@ -4249,7 +4249,6 @@ buffer_inserted_text (ClutterTextBuffer *buffer, ClutterTextPrivate *priv; gint new_position; gint new_selection_bound; - gsize n_bytes; priv = self->priv; if (priv->position >= 0 || priv->selection_bound >= 0) @@ -4266,10 +4265,6 @@ buffer_inserted_text (ClutterTextBuffer *buffer, clutter_text_set_positions (self, new_position, new_selection_bound); } - n_bytes = g_utf8_offset_to_pointer (chars, n_chars) - chars; - g_signal_emit (self, text_signals[INSERT_TEXT], 0, chars, - n_bytes, &position); - /* TODO: What are we supposed to with the out value of position? */ } @@ -5886,6 +5881,33 @@ clutter_text_get_max_length (ClutterText *self) return clutter_text_buffer_get_max_length (get_buffer (self)); } +static void +clutter_text_real_insert_text (ClutterText *self, + guint start_pos, + const gchar *chars, + guint n_chars) +{ + gsize n_bytes; + + n_bytes = g_utf8_offset_to_pointer (chars, n_chars) - chars; + + /* + * insert-text is emitted here instead of as part of a + * buffer_inserted_text() callback because that should be emitted + * before the buffer changes, while ClutterTextBuffer::deleted-text + * is emitter after. See BG#722220 for more info. + */ + g_signal_emit (self, text_signals[INSERT_TEXT], 0, chars, + n_bytes, &start_pos); + + /* + * The actual insertion from the buffer. This will end firing the + * following signal handlers: buffer_inserted_text(), + * buffer_notify_text(), buffer_notify_max_length() + */ + clutter_text_buffer_insert_text (get_buffer (self), start_pos, chars, n_chars); +} + /** * clutter_text_insert_unichar: * @self: a #ClutterText @@ -5908,11 +5930,12 @@ clutter_text_insert_unichar (ClutterText *self, new = g_string_new (""); g_string_append_unichar (new, wc); - clutter_text_buffer_insert_text (get_buffer (self), priv->position, new->str, 1); + clutter_text_real_insert_text (self, priv->position, new->str, 1); g_string_free (new, TRUE); } + /** * clutter_text_insert_text: * @self: a #ClutterText @@ -5936,8 +5959,7 @@ clutter_text_insert_text (ClutterText *self, g_return_if_fail (CLUTTER_IS_TEXT (self)); g_return_if_fail (text != NULL); - clutter_text_buffer_insert_text (get_buffer (self), position, text, - g_utf8_strlen (text, -1)); + clutter_text_real_insert_text (self, position, text, g_utf8_strlen (text, -1)); } static -- cgit v1.2.1