From b578c78eff41bd2dbedf459a102e05eec78b7f7c Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Wed, 22 Sep 2021 17:08:02 -0700 Subject: [PATCH] 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 --- gtk/gtktexthistory.c | 6 ++++++ testsuite/gtk/texthistory.c | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/gtk/gtktexthistory.c b/gtk/gtktexthistory.c index 61ccc33f08..3b9379ccc3 100644 --- a/gtk/gtktexthistory.c +++ b/gtk/gtktexthistory.c @@ -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; } diff --git a/testsuite/gtk/texthistory.c b/testsuite/gtk/texthistory.c index cca4008196..a740d3523b 100644 --- a/testsuite/gtk/texthistory.c +++ b/testsuite/gtk/texthistory.c @@ -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 (); }