gtktexthistory: restore 'modified' flag on redo

When redoing a history entry, its `is_modified` flag is not
reflected to the history state tracker. So GtkTextBuffers may
expose a modified=FALSE status, despite a change was actually
applied to the buffer.

For the undo case, an `is_modified_set` flag was set on the last
entry of the undo queue when a change of the modified state of
the history is requested. This commit does the same on the first
entry of the redo queue.

Closes #5777
This commit is contained in:
G.Willems
2023-08-17 22:26:00 +02:00
parent b948e03e8a
commit b4977decc1
2 changed files with 42 additions and 0 deletions

View File

@@ -1100,6 +1100,18 @@ gtk_text_history_modified_changed (GtkTextHistory *self,
peek->is_modified_set = TRUE;
}
if ((peek = g_queue_peek_head (&self->redo_queue)))
{
if (peek->kind == ACTION_KIND_BARRIER)
{
if (!(peek = peek->link.next->data))
return;
}
peek->is_modified = TRUE;
peek->is_modified_set = TRUE;
}
self->is_modified = !!modified;
self->is_modified_set = TRUE;

View File

@@ -635,6 +635,35 @@ test_issue_4575 (void)
run_test (commands, G_N_ELEMENTS (commands), 0);
}
static void
test_issue_5777 (void)
{
static const Command commands[] = {
{ MODIFIED, -1, -1, NULL, NULL, UNSET, UNSET, SET },
{ INSERT_SEQ, 0, -1, "this is a test\nmore", "this is a test\nmore", SET, UNSET, SET },
{ UNDO, -1, -1, NULL, "this is a test\n", SET, SET, SET },
{ UNMODIFIED, -1, -1, NULL, NULL, SET, SET, UNSET },
{ REDO, -1, -1, NULL, "this is a test\nmore", SET, UNSET, SET },
{ UNDO, -1, -1, NULL, "this is a test\n", SET, SET, UNSET },
{ REDO, -1, -1, NULL, "this is a test\nmore", SET, UNSET, SET },
{ UNDO, -1, -1, NULL, "this is a test\n", SET, SET, UNSET },
{ MODIFIED, -1, -1, NULL, NULL, SET, SET, SET },
{ REDO, -1, -1, NULL, "this is a test\nmore", SET, UNSET, SET },
{ UNMODIFIED, -1, -1, NULL, NULL, SET, UNSET, UNSET },
{ UNDO, -1, -1, NULL, "this is a test\n", SET, SET, SET },
{ REDO, -1, -1, NULL, "this is a test\nmore", SET, UNSET, UNSET },
{ UNDO, -1, -1, NULL, "this is a test\n", SET, SET, SET },
{ UNDO, -1, -1, NULL, "this is a test", SET, SET, SET },
{ UNMODIFIED, -1, -1, NULL, NULL, SET, SET, UNSET },
{ UNDO, -1, -1, NULL, "this is a", SET, SET, SET },
{ REDO, -1, -1, NULL, "this is a test", SET, SET, UNSET },
{ REDO, -1, -1, NULL, "this is a test\n", SET, SET, SET },
{ REDO, -1, -1, NULL, "this is a test\nmore", SET, UNSET, SET },
};
run_test (commands, G_N_ELEMENTS (commands), 4);
}
int
main (int argc,
char *argv[])
@@ -657,6 +686,7 @@ main (int argc,
g_test_add_func ("/Gtk/TextHistory/test14", test14);
g_test_add_func ("/Gtk/TextHistory/issue_4276", test_issue_4276);
g_test_add_func ("/Gtk/TextHistory/issue_4575", test_issue_4575);
g_test_add_func ("/Gtk/TextHistory/issue_5777", test_issue_5777);
return g_test_run ();
}