[gtk/entry-fix] text: Make Emoji insertion work properly



commit e41596d6a1a6fd0124b30f8eefb8c72450e69f5c
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed May 1 05:13:52 2019 +0000

    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.

 gtk/gtktext.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
---
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));
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]