[geany/geany] 44eecc: Merge pull request #187 from artros/bug/clear-redo-on-edit

Colomban Wendling git-noreply at xxxxx
Wed Jan 28 13:30:43 UTC 2015


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Wed, 28 Jan 2015 13:30:43 UTC
Commit:      44eecc25c3352d0197b94f1458d8496bc48668ae
             https://github.com/geany/geany/commit/44eecc25c3352d0197b94f1458d8496bc48668ae

Log Message:
-----------
Merge pull request #187 from artros/bug/clear-redo-on-edit

Clear redo stack on edit


Modified Paths:
--------------
    src/document.c

Modified: src/document.c
54 lines changed, 30 insertions(+), 24 deletions(-)
===================================================================
@@ -122,7 +122,9 @@ enum
 static guint doc_id_counter = 0;
 
 
+static void document_undo_clear_stack(GTrashStack **stack);
 static void document_undo_clear(GeanyDocument *doc);
+static void document_undo_add_internal(GeanyDocument *doc, guint type, gpointer data);
 static void document_redo_add(GeanyDocument *doc, guint type, gpointer data);
 static gboolean remove_page(guint page_num);
 static GtkWidget* document_show_message(GeanyDocument *doc, GtkMessageType msgtype,
@@ -2701,14 +2703,14 @@ void document_set_encoding(GeanyDocument *doc, const gchar *new_encoding)
  * to the encoding or the Unicode BOM (which are Scintilla independet).
  * All Scintilla events are stored in the undo / redo buffer and are passed through. */
 
-/* Clears the Undo and Redo buffer (to be called when reloading or closing the document) */
-void document_undo_clear(GeanyDocument *doc)
+/* Clears an Undo or Redo buffer. */
+void document_undo_clear_stack(GTrashStack **stack)
 {
 	undo_action *a;
 
-	while (g_trash_stack_height(&doc->priv->undo_actions) > 0)
+	while (g_trash_stack_height(stack) > 0)
 	{
-		a = g_trash_stack_pop(&doc->priv->undo_actions);
+		a = g_trash_stack_pop(stack);
 		if (G_LIKELY(a != NULL))
 		{
 			switch (a->type)
@@ -2719,30 +2721,25 @@ void document_undo_clear(GeanyDocument *doc)
 			g_free(a);
 		}
 	}
-	doc->priv->undo_actions = NULL;
+	*stack = NULL;
+}
 
-	while (g_trash_stack_height(&doc->priv->redo_actions) > 0)
-	{
-		a = g_trash_stack_pop(&doc->priv->redo_actions);
-		if (G_LIKELY(a != NULL))
-		{
-			switch (a->type)
-			{
-				case UNDO_ENCODING: g_free(a->data); break;
-				default: break;
-			}
-			g_free(a);
-		}
-	}
-	doc->priv->redo_actions = NULL;
+/* Clears the Undo and Redo buffer (to be called when reloading or closing the document) */
+void document_undo_clear(GeanyDocument *doc)
+{
+	document_undo_clear_stack(&doc->priv->undo_actions);
+	document_undo_clear_stack(&doc->priv->redo_actions);
 
 	if (! main_status.quitting && doc->editor != NULL)
 		document_set_text_changed(doc, FALSE);
 }
 
 
-/* note: this is called on SCN_MODIFIED notifications */
-void document_undo_add(GeanyDocument *doc, guint type, gpointer data)
+/* Adds an undo action without clearing the redo stack. This function should
+ * not be called directly, generally (use document_undo_add() instead), but is
+ * used by document_redo() in order not to erase the redo stack while moving
+ * an action from the redo stack to the undo stack. */
+void document_undo_add_internal(GeanyDocument *doc, guint type, gpointer data)
 {
 	undo_action *action;
 
@@ -2761,6 +2758,15 @@ void document_undo_add(GeanyDocument *doc, guint type, gpointer data)
 	ui_update_popup_reundo_items(doc);
 }
 
+/* note: this is called on SCN_MODIFIED notifications */
+void document_undo_add(GeanyDocument *doc, guint type, gpointer data)
+{
+	/* Clear the redo actions stack before adding the undo action. */
+	document_undo_clear_stack(&doc->priv->redo_actions);
+
+	document_undo_add_internal(doc, type, data);
+}
+
 
 gboolean document_can_undo(GeanyDocument *doc)
 {
@@ -2872,14 +2878,14 @@ void document_redo(GeanyDocument *doc)
 		{
 			case UNDO_SCINTILLA:
 			{
-				document_undo_add(doc, UNDO_SCINTILLA, NULL);
+				document_undo_add_internal(doc, UNDO_SCINTILLA, NULL);
 
 				sci_redo(doc->editor->sci);
 				break;
 			}
 			case UNDO_BOM:
 			{
-				document_undo_add(doc, UNDO_BOM, GINT_TO_POINTER(doc->has_bom));
+				document_undo_add_internal(doc, UNDO_BOM, GINT_TO_POINTER(doc->has_bom));
 
 				doc->has_bom = GPOINTER_TO_INT(action->data);
 				ui_update_statusbar(doc, -1);
@@ -2888,7 +2894,7 @@ void document_redo(GeanyDocument *doc)
 			}
 			case UNDO_ENCODING:
 			{
-				document_undo_add(doc, UNDO_ENCODING, g_strdup(doc->encoding));
+				document_undo_add_internal(doc, UNDO_ENCODING, g_strdup(doc->encoding));
 
 				document_set_encoding(doc, (const gchar*)action->data);
 



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list