[gtk/preedit-selection-fix: 5/8] text: Delete selection when preedit starts




commit 447203ce525ff95e916c6106818df2836c7d9b1f
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Mar 4 14:49:14 2021 -0500

    text: Delete selection when preedit starts
    
    This prevents confusing misrendering when the preedit text
    pushes the selection text out of the rendered selection.
    
    Fixes: #1123

 gtk/gtktext.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
---
diff --git a/gtk/gtktext.c b/gtk/gtktext.c
index f2f1f854b0..7791029e52 100644
--- a/gtk/gtktext.c
+++ b/gtk/gtktext.c
@@ -418,6 +418,8 @@ static void     direction_changed           (GdkDevice       *keyboard,
 static void     gtk_text_commit_cb               (GtkIMContext *context,
                                                   const char   *str,
                                                   GtkText      *self);
+static void     gtk_text_preedit_start_cb        (GtkIMContext *context,
+                                                  GtkText      *self);
 static void     gtk_text_preedit_changed_cb      (GtkIMContext *context,
                                                   GtkText      *self);
 static gboolean gtk_text_retrieve_surrounding_cb (GtkIMContext *context,
@@ -1843,6 +1845,8 @@ gtk_text_init (GtkText *self)
    */
   priv->im_context = gtk_im_multicontext_new ();
 
+  g_signal_connect (priv->im_context, "preedit-start",
+                    G_CALLBACK (gtk_text_preedit_start_cb), self);
   g_signal_connect (priv->im_context, "commit",
                     G_CALLBACK (gtk_text_commit_cb), self);
   g_signal_connect (priv->im_context, "preedit-changed",
@@ -4150,6 +4154,13 @@ direction_changed (GdkDevice  *device,
 /* IM Context Callbacks
  */
 
+static void
+gtk_text_preedit_start_cb (GtkIMContext *context,
+                           GtkText      *self)
+{
+  gtk_text_delete_selection (self);
+}
+
 static void
 gtk_text_commit_cb (GtkIMContext *context,
                     const char   *str,


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