[gtk/text-emoji-history] text: Treat Emoji insertion like clipboard



commit a838a54dca7673d561a62f53695837082834a179
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Feb 17 15:05:09 2020 -0500

    text: Treat Emoji insertion like clipboard
    
    Enter the Emoji inseration in the undo history.
    Also, stop stashing away the selection when we
    pop up the Emoji chooser, and use the selection
    as-is when we insert the Emoji.

 gtk/gtktext.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtktext.c b/gtk/gtktext.c
index b671c9a39f..4f428ba8f9 100644
--- a/gtk/gtktext.c
+++ b/gtk/gtktext.c
@@ -6779,20 +6779,23 @@ emoji_picked (GtkEmojiChooser *chooser,
               const char      *text,
               GtkText         *self)
 {
-  int current_pos;
-  int selection_bound;
+  int pos;
 
-  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"));
+  GtkTextPrivate *priv = gtk_text_get_instance_private (self);
 
-  gtk_text_set_positions (self, current_pos, selection_bound);
-  gtk_text_enter_text (self, text);
+  begin_change (self);
+  if (priv->selection_bound != priv->current_pos)
+    gtk_text_delete_selection (self);
+
+  pos = priv->current_pos;
+  gtk_text_insert_text (self, text, -1, &pos);
+  gtk_text_set_selection_bounds (self, pos, pos);
+  end_change (self);
 }
 
 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)
@@ -6808,9 +6811,6 @@ gtk_text_insert_emoji (GtkText *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]