gtktexthistory: restore 'modified' flag on redo
authorG.Willems <g.willems.dev@laposte.net>
Thu, 17 Aug 2023 20:26:00 +0000 (22:26 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 24 Aug 2023 14:24:41 +0000 (10:24 -0400)
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
testsuite/gtk/texthistory.c

index 8cd6f85e91be22218e76b78b294c7f6eb469fda4..292147a04af6711545a07bfd96d3b70c7783045a 100644 (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;
 
index ad623d0e2ae8b772f5673cc865ad4ac1fc9f6218..aacf72cccbb915703210b84d38a0de0029f7d639 100644 (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 ();
 }