summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Piñeiro <apinheiro@igalia.com>2014-01-16 18:04:22 +0100
committerAlejandro Piñeiro <apinheiro@igalia.com>2014-01-17 13:09:48 +0100
commit798f4ef321c980a22220cce49a0d744ee85172b6 (patch)
tree01e674ca4b38c1b32f92749a41ef72f099345c3f
parent3fe9c91da9ed24d4ca19b6edcd450dfa5d764ceb (diff)
downloadclutter-798f4ef321c980a22220cce49a0d744ee85172b6.tar.gz
clutter-text: emitting ClutterText::insert-text before actual changes on the text
https://bugzilla.gnome.org/show_bug.cgi?id=722220 (cherry picked from commit cadbeceff0a729cdeafd84db237ed44ad782e820) Signed-off-by: Alejandro Piñeiro <apinheiro@igalia.com>
-rw-r--r--clutter/clutter-text.c38
1 files 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