Merge branch 'emoji-insert-fix' into 'master'

textview: Make insert-emoji replace the selection

Closes #2996

See merge request GNOME/gtk!2350
This commit is contained in:
Matthias Clasen 2020-08-03 01:40:43 +00:00
commit 89c10e092a

View File

@ -9616,6 +9616,21 @@ gtk_text_view_get_monospace (GtkTextView *text_view)
return gtk_widget_has_css_class (GTK_WIDGET (text_view), GTK_STYLE_CLASS_MONOSPACE);
}
static void
emoji_picked (GtkEmojiChooser *chooser,
const char *text,
GtkTextView *self)
{
GtkTextBuffer *buffer;
buffer = get_buffer (self);
gtk_text_buffer_begin_user_action (buffer);
gtk_text_buffer_delete_selection (buffer, TRUE, TRUE);
gtk_text_buffer_insert_at_cursor (buffer, text, -1);
gtk_text_buffer_end_user_action (buffer);
}
static void
gtk_text_view_insert_emoji (GtkTextView *text_view)
{
@ -9634,8 +9649,7 @@ gtk_text_view_insert_emoji (GtkTextView *text_view)
g_object_set_data (G_OBJECT (text_view), "gtk-emoji-chooser", chooser);
gtk_widget_set_parent (chooser, GTK_WIDGET (text_view));
g_signal_connect_swapped (chooser, "emoji-picked",
G_CALLBACK (gtk_text_view_insert_at_cursor), text_view);
g_signal_connect (chooser, "emoji-picked", G_CALLBACK (emoji_picked), text_view);
}
buffer = get_buffer (text_view);