[clutter/clutter-1.18] clutter-text: emitting ClutterText::insert-text before actual changes on the text



commit cadbeceff0a729cdeafd84db237ed44ad782e820
Author: Alejandro Piñeiro <apinheiro igalia com>
Date:   Thu Jan 16 18:04:22 2014 +0100

    clutter-text: emitting ClutterText::insert-text before actual changes on the text
    
    https://bugzilla.gnome.org/show_bug.cgi?id=722220

 clutter/clutter-text.c |   38 ++++++++++++++++++++++++++++++--------
 1 files changed, 30 insertions(+), 8 deletions(-)
---
diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c
index 417f60a..b97720a 100644
--- a/clutter/clutter-text.c
+++ b/clutter/clutter-text.c
@@ -4257,7 +4257,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)
@@ -4274,10 +4273,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? */
 }
 
@@ -5894,6 +5889,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
@@ -5916,11 +5938,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
@@ -5944,8 +5967,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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]