From c018af302376e6c3a57525984665812a82f6327c Mon Sep 17 00:00:00 2001 From: "G.Willems" Date: Thu, 17 Aug 2023 22:26:00 +0200 Subject: [PATCH] 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 --- gtk/gtktexthistory.c | 12 ++++++++++++ testsuite/gtk/texthistory.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/gtk/gtktexthistory.c b/gtk/gtktexthistory.c index 8cd6f85e91..292147a04a 100644 --- a/gtk/gtktexthistory.c +++ b/gtk/gtktexthistory.c @@ -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; diff --git a/testsuite/gtk/texthistory.c b/testsuite/gtk/texthistory.c index ad623d0e2a..aacf72cccb 100644 --- a/testsuite/gtk/texthistory.c +++ b/testsuite/gtk/texthistory.c @@ -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 (); } -- 2.30.2