texthistory: add barriers after final grouping

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
This commit is contained in:
Christian Hergert 2021-09-22 17:08:02 -07:00
parent d7db3f1546
commit b578c78eff
2 changed files with 24 additions and 0 deletions

View 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;
}

View File

@ -606,6 +606,23 @@ test14 (void)
g_free (fill_after_2);
}
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[])
@ -626,6 +643,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 ();
}