[gtk/emoji-insert-fix] textview: Make insert-emoji replace the selection
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/emoji-insert-fix] textview: Make insert-emoji replace the selection
- Date: Mon, 3 Aug 2020 00:49:40 +0000 (UTC)
commit 348a38a8769dacf88e4f69e07fbe37e4ddfd6732
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Aug 2 20:48:14 2020 -0400
textview: Make insert-emoji replace the selection
This is the expected behavior, and matches what
GtkText does.
Fixes: #2996
gtk/gtktextview.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index c0e2749d4f..5aef271df6 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]