mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-29 15:01:23 +00:00
text: Make Emoji insertion work properly
We are now getting focus-out and focus-in events when the Emoji chooser is shown and hidden, and this is causing the text to select-on-entry before inserting the Emoji, which then deletes the selection. Avoid this by saving and restoring the selection when presenting the Emoji chooser.
This commit is contained in:
parent
0fa4d54316
commit
e41596d6a1
@ -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));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user