[gtksourceview/wip/undo-redo-fix] UndoManager: fix bug with modified inside not undoable action



commit 1b42e15013df095d820e8a3ad18f752888310fd1
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Jan 2 18:57:42 2015 +0100

    UndoManager: fix bug with modified inside not undoable action
    
    The modified-changed callback is blocked during a not undoable action
    (which is fine), but when unblocking the signals the modified state must
    be set.

 gtksourceview/gtksourceundomanagerdefault.c |    2 ++
 tests/test-undo-manager.c                   |   20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/gtksourceview/gtksourceundomanagerdefault.c b/gtksourceview/gtksourceundomanagerdefault.c
index 2d336bf..379579a 100644
--- a/gtksourceview/gtksourceundomanagerdefault.c
+++ b/gtksourceview/gtksourceundomanagerdefault.c
@@ -1540,6 +1540,7 @@ gtk_source_undo_manager_end_not_undoable_action_impl (GtkSourceUndoManager *undo
        {
                unblock_signal_handlers (manager);
                clear_all (manager);
+               modified_changed_cb (manager->priv->buffer, manager);
        }
 }
 
@@ -1573,6 +1574,7 @@ gtk_source_undo_manager_default_set_max_undo_levels (GtkSourceUndoManagerDefault
                else if (manager->priv->max_undo_levels == 0)
                {
                        unblock_signal_handlers (manager);
+                       modified_changed_cb (manager->priv->buffer, manager);
                }
 
                manager->priv->max_undo_levels = max_undo_levels;
diff --git a/tests/test-undo-manager.c b/tests/test-undo-manager.c
index b66300f..ac2aaa7 100644
--- a/tests/test-undo-manager.c
+++ b/tests/test-undo-manager.c
@@ -614,6 +614,26 @@ test_modified (void)
        g_assert (gtk_text_buffer_get_modified (text_buffer));
 
        g_object_unref (source_buffer);
+
+       /* Inside not undoable action. */
+       source_buffer = gtk_source_buffer_new (NULL);
+       text_buffer = GTK_TEXT_BUFFER (source_buffer);
+       gtk_source_buffer_set_max_undo_levels (source_buffer, -1);
+
+       gtk_text_buffer_set_modified (text_buffer, TRUE);
+
+       gtk_source_buffer_begin_not_undoable_action (source_buffer);
+       insert_text (source_buffer, "a\n");
+       gtk_text_buffer_set_modified (text_buffer, FALSE);
+       gtk_source_buffer_end_not_undoable_action (source_buffer);
+
+       insert_text (source_buffer, "b\n");
+       g_assert (gtk_text_buffer_get_modified (text_buffer));
+
+       gtk_source_buffer_undo (source_buffer);
+       g_assert (!gtk_text_buffer_get_modified (text_buffer));
+
+       g_object_unref (source_buffer);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]