gtktextview: Shuffle the places doing IM reset
authorCarlos Garnacho <carlosg@gnome.org>
Wed, 17 Aug 2022 22:58:14 +0000 (00:58 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Thu, 18 Aug 2022 17:07:12 +0000 (19:07 +0200)
During text widget manipulation (inserting or deleting text via keyboard)
the IM context is reset somewhat early, before the actual change took place.
This makes IM lag behind in terms of surrounding text and cursor position.

Shuffle these IM reset calls so that they happen after the changes, and
ensure that the IM is actually reset, since that is currently toggled on
a pretty narrow set of circumstances.

Also, fix a bug during GtkEventControllerKey::im-update where the condition
on cursor position editability to reset the IM context was inverted.

gtk/gtktextview.c

index bb053696e205036a4a83b03dd2a0e8bdef1e2096..bfd3616530b884923914201d5386a2f2e55bfe11 100644 (file)
@@ -5533,7 +5533,7 @@ gtk_text_view_key_controller_im_update (GtkEventControllerKey *controller,
   can_insert = gtk_text_iter_can_insert (&iter, priv->editable);
 
   priv->need_im_reset = TRUE;
-  if (!can_insert)
+  if (can_insert)
     gtk_text_view_reset_im_context (text_view);
 }
 
@@ -6366,8 +6366,6 @@ gtk_text_view_move_cursor (GtkTextView     *text_view,
       return;
     }
 
-  gtk_text_view_reset_im_context (text_view);
-
   if (step == GTK_MOVEMENT_PAGES)
     {
       if (!gtk_text_view_scroll_pages (text_view, count, extend_selection))
@@ -6551,6 +6549,9 @@ gtk_text_view_move_cursor (GtkTextView     *text_view,
 
   gtk_text_view_check_cursor_blink (text_view);
   gtk_text_view_pend_cursor_blink (text_view);
+
+  priv->need_im_reset = TRUE;
+  gtk_text_view_reset_im_context (text_view);
 }
 
 static void
@@ -6841,14 +6842,16 @@ gtk_text_view_delete_from_cursor (GtkTextView   *text_view,
 
   priv = text_view->priv;
 
-  gtk_text_view_reset_im_context (text_view);
-
   if (type == GTK_DELETE_CHARS)
     {
       /* Char delete deletes the selection, if one exists */
       if (gtk_text_buffer_delete_selection (get_buffer (text_view), TRUE,
                                             priv->editable))
-        return;
+        {
+          priv->need_im_reset = TRUE;
+          gtk_text_view_reset_im_context (text_view);
+          return;
+        }
     }
 
   gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
@@ -6975,6 +6978,9 @@ gtk_text_view_delete_from_cursor (GtkTextView   *text_view,
     {
       gtk_widget_error_bell (GTK_WIDGET (text_view));
     }
+
+  priv->need_im_reset = TRUE;
+  gtk_text_view_reset_im_context (text_view);
 }
 
 static void
@@ -6985,12 +6991,14 @@ gtk_text_view_backspace (GtkTextView *text_view)
 
   priv = text_view->priv;
 
-  gtk_text_view_reset_im_context (text_view);
-
   /* Backspace deletes the selection, if one exists */
   if (gtk_text_buffer_delete_selection (get_buffer (text_view), TRUE,
                                         priv->editable))
-    return;
+    {
+      priv->need_im_reset = TRUE;
+      gtk_text_view_reset_im_context (text_view);
+      return;
+    }
 
   gtk_text_buffer_get_iter_at_mark (get_buffer (text_view),
                                     &insert,
@@ -7003,6 +7011,9 @@ gtk_text_view_backspace (GtkTextView *text_view)
       DV(g_print (G_STRLOC": scrolling onscreen\n"));
       gtk_text_view_scroll_mark_onscreen (text_view,
                                           gtk_text_buffer_get_insert (get_buffer (text_view)));
+
+      priv->need_im_reset = TRUE;
+      gtk_text_view_reset_im_context (text_view);
     }
   else
     {