[gtk/gtk-4-6: 4/15] gtktext: Avoid early IM reset on updates




commit 452d93c7ea869a6f8e346995ba8bb34931906440
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Sep 6 21:43:14 2022 +0200

    gtktext: Avoid early IM reset on updates
    
    Resetting the IM on IM updates is too eager and indeed the simple
    IM context doesn't like that this happens in the middle of dead
    key handling.
    
    We however want to reset the IM after actual text buffer changes
    (say, a committed string) moved the cursor position, altered the
    surrounding text, etc. So that the IM implementation does know to
    update its state.
    
    Since there is going to be an actual IM reset anyways, it does
    no longer make sense to try to preserve the old priv->need_im_reset
    status during commit handling.
    
    Fixes: 52ac71b972 ("gtktextview: Shuffle the places doing IM reset")
    Closes: https://gitlab.gnome.org/GNOME/gtk/-/issues/5133

 gtk/gtktext.c     |  4 ----
 gtk/gtktextview.c | 10 +---------
 2 files changed, 1 insertion(+), 13 deletions(-)
---
diff --git a/gtk/gtktext.c b/gtk/gtktext.c
index 348f968466..e4e4c90917 100644
--- a/gtk/gtktext.c
+++ b/gtk/gtktext.c
@@ -4350,10 +4350,8 @@ gtk_text_enter_text (GtkText    *self,
 {
   GtkTextPrivate *priv = gtk_text_get_instance_private (self);
   int tmp_pos;
-  gboolean old_need_im_reset;
   guint text_length;
 
-  old_need_im_reset = priv->need_im_reset;
   priv->need_im_reset = FALSE;
 
   if (priv->selection_bound != priv->current_pos)
@@ -4371,8 +4369,6 @@ gtk_text_enter_text (GtkText    *self,
   tmp_pos = priv->current_pos;
   gtk_editable_insert_text (GTK_EDITABLE (self), str, strlen (str), &tmp_pos);
   gtk_text_set_selection_bounds (self, tmp_pos, tmp_pos);
-
-  priv->need_im_reset = old_need_im_reset;
 }
 
 /* All changes to priv->current_pos and priv->selection_bound
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index f7b1687581..06f61eaab5 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -5516,17 +5516,8 @@ gtk_text_view_key_controller_im_update (GtkEventControllerKey *controller,
                                         GtkTextView           *text_view)
 {
   GtkTextViewPrivate *priv = text_view->priv;
-  GtkTextMark *insert;
-  GtkTextIter iter;
-  gboolean can_insert;
-
-  insert = gtk_text_buffer_get_insert (get_buffer (text_view));
-  gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, insert);
-  can_insert = gtk_text_iter_can_insert (&iter, priv->editable);
 
   priv->need_im_reset = TRUE;
-  if (can_insert)
-    gtk_text_view_reset_im_context (text_view);
 }
 
 static gboolean
@@ -8486,6 +8477,7 @@ gtk_text_view_commit_handler (GtkIMContext  *context,
   gtk_text_view_commit_text (text_view, str);
   gtk_text_view_reset_blink_time (text_view);
   gtk_text_view_pend_cursor_blink (text_view);
+  gtk_im_context_reset (context);
 }
 
 static void


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