diff --git a/gtk/gtktext.c b/gtk/gtktext.c index 75e17e11aa..b5d37bbd77 100644 --- a/gtk/gtktext.c +++ b/gtk/gtktext.c @@ -6596,9 +6596,25 @@ gtk_text_get_tabs (GtkText *self) return priv->tabs; } +static void +emoji_picked (GtkEmojiChooser *chooser, + const char *text, + GtkText *self) +{ + int current_pos; + int selection_bound; + + current_pos = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (chooser), "current-pos")); + selection_bound = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (chooser), "selection-bound")); + + gtk_text_set_positions (self, current_pos, selection_bound); + gtk_text_enter_text (self, text); +} + static void gtk_text_insert_emoji (GtkText *self) { + GtkTextPrivate *priv = gtk_text_get_instance_private (self); GtkWidget *chooser; if (gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_EMOJI_CHOOSER) != NULL) @@ -6611,9 +6627,12 @@ gtk_text_insert_emoji (GtkText *self) g_object_set_data (G_OBJECT (self), "gtk-emoji-chooser", chooser); gtk_popover_set_relative_to (GTK_POPOVER (chooser), GTK_WIDGET (self)); - g_signal_connect_swapped (chooser, "emoji-picked", G_CALLBACK (gtk_text_enter_text), self); + g_signal_connect (chooser, "emoji-picked", G_CALLBACK (emoji_picked), self); } + g_object_set_data (G_OBJECT (chooser), "current-pos", GINT_TO_POINTER (priv->current_pos)); + g_object_set_data (G_OBJECT (chooser), "selection-bound", GINT_TO_POINTER (priv->selection_bound)); + gtk_popover_popup (GTK_POPOVER (chooser)); }