From bbc7d20f5ecff80f4000557b976e3153f6286252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Pi=C3=B1eiro?= Date: Thu, 16 Jan 2014 17:39:02 +0100 Subject: [PATCH] clutter-text: emitting ClutterText::delete-text before actual changes on the text https://bugzilla.gnome.org/show_bug.cgi?id=722220 --- clutter/clutter-text.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c index ea0ad4d78..417f60a88 100644 --- a/clutter/clutter-text.c +++ b/clutter/clutter-text.c @@ -4305,8 +4305,6 @@ buffer_deleted_text (ClutterTextBuffer *buffer, if (priv->position != new_position || priv->selection_bound != new_selection_bound) clutter_text_set_positions (self, new_position, new_selection_bound); } - - g_signal_emit (self, text_signals[DELETE_TEXT], 0, position, position + n_chars); } static void @@ -5950,6 +5948,29 @@ clutter_text_insert_text (ClutterText *self, g_utf8_strlen (text, -1)); } +static +void clutter_text_real_delete_text (ClutterText *self, + gssize start_pos, + gssize end_pos) +{ + /* + * delete-text is emitted here instead of as part of a + * buffer_deleted_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[DELETE_TEXT], 0, start_pos, end_pos); + + /* + * The actual deletion from the buffer. This will end firing the + * following signal handlers: buffer_deleted_text(), + * buffer_notify_text(), buffer_notify_max_length() + */ + clutter_text_buffer_delete_text (get_buffer (self), start_pos, end_pos - start_pos); +} + + + /** * clutter_text_delete_text: * @self: a #ClutterText @@ -5971,7 +5992,7 @@ clutter_text_delete_text (ClutterText *self, { g_return_if_fail (CLUTTER_IS_TEXT (self)); - clutter_text_buffer_delete_text (get_buffer (self), start_pos, end_pos - start_pos); + clutter_text_real_delete_text (self, start_pos, end_pos); } /** @@ -5997,7 +6018,7 @@ clutter_text_delete_chars (ClutterText *self, priv = self->priv; - clutter_text_buffer_delete_text (get_buffer (self), priv->position, n_chars); + clutter_text_real_delete_text (self, priv->position, n_chars); if (priv->position > 0) clutter_text_set_cursor_position (self, priv->position - n_chars);