gtktext: Avoid early IM reset on updates
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 6 Sep 2022 19:43:14 +0000 (21:43 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Tue, 6 Sep 2022 20:17:40 +0000 (22:17 +0200)
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
gtk/gtktextview.c

index 0e10b9e9474abdb759934855ce2b36d89e8bcd53..5fbc3e95fef0c5a79a3d8503d11458854be8fe84 100644 (file)
@@ -4315,10 +4315,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)
@@ -4336,8 +4334,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
index bfd3616530b884923914201d5386a2f2e55bfe11..1684b3288ef8ab389a0c667253d8d9d908871ebf 100644 (file)
@@ -5524,17 +5524,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
@@ -8494,6 +8485,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