texthistory: add barriers after final grouping
authorChristian Hergert <chergert@redhat.com>
Thu, 23 Sep 2021 00:08:02 +0000 (17:08 -0700)
committerChristian Hergert <chergert@redhat.com>
Fri, 24 Sep 2021 23:37:59 +0000 (16:37 -0700)
We don't want to allow new items to be grouped into a previous action
group after the end_user_action() is called. This ensures that we add a
barrier action in those conditions.

Fixes #4276

gtk/gtktexthistory.c
testsuite/gtk/texthistory.c

index 61ccc33f08511430fa76243535072e803d8abb9b..3b9379ccc3d255912b68a0aa6aa8038604902603 100644 (file)
@@ -224,6 +224,12 @@ action_chain (Action   *action,
 
       if (other->kind == ACTION_KIND_BARRIER)
         {
+          /* If we're not in a user action, this barrier is meant to
+           * stop items from coallescing into this group.
+           */
+          if (!in_user_action && action->u.group.depth == 0)
+            return FALSE;
+
           action_free (other);
           return TRUE;
         }
index c64c803083d0c8e674da62002c5c22ea8e94eac1..505e6d789361098d0c6410dca830d94102e4d1e2 100644 (file)
@@ -604,6 +604,23 @@ test14 (void)
   g_free (fill);
 }
 
+static void
+test_issue_4276 (void)
+{
+  const Command commands[] = {
+    { INSERT, 0, -1, "this is some text", "this is some text", SET, UNSET, UNSET },
+    { SELECT, 0, 17, NULL, "this is some text", SET, UNSET, UNSET },
+    { BEGIN_USER, -1, -1, NULL, NULL, UNSET, UNSET, UNSET },
+    { DELETE_KEY, 0, 17, "this is some text", "", UNSET, UNSET, UNSET },
+    { INSERT, 0, -1, "z", "z", UNSET, UNSET, UNSET },
+    { END_USER, -1, -1, NULL, NULL, SET, UNSET, UNSET },
+    { INSERT, 1, -1, "zzz", "zzzz", SET, UNSET, UNSET },
+    { UNDO, -1, -1, NULL, "z", SET, SET, UNSET },
+  };
+
+  run_test (commands, G_N_ELEMENTS (commands), 0);
+}
+
 int
 main (int   argc,
       char *argv[])
@@ -624,6 +641,7 @@ main (int   argc,
   g_test_add_func ("/Gtk/TextHistory/test12", test12);
   g_test_add_func ("/Gtk/TextHistory/test13", test13);
   g_test_add_func ("/Gtk/TextHistory/test14", test14);
+  g_test_add_func ("/Gtk/TextHistory/issue_4276", test_issue_4276);
 
   return g_test_run ();
 }