[gnumeric] undo: avoid undo entries when nothing changes.



commit 4cb21c751f1b6f9b3507b478d26aabdd01440b59
Author: Morten Welinder <terra gnome org>
Date:   Fri Aug 13 20:05:49 2010 -0400

    undo: avoid undo entries when nothing changes.

 ChangeLog      |   14 +++++++++---
 src/commands.c |   60 +++++++++++++++++++++++++++++++++++--------------------
 2 files changed, 48 insertions(+), 26 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ac0f61f..d8ac66a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-08-13  Morten Welinder  <terra gnome org>
+
+	* src/commands.c (cmd_set_text_full): Restore check for actual
+	changes.  Fixes #626797.
+
 2010-08-13  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* src/commands.c (cmd_set_text_full_check_texpr): new
@@ -18,10 +23,11 @@
 
 2010-08-13  Andreas J. Guelzow <aguelzow pyrshep ca>
 
-	* src/colrow.c (colrow_set_sizes): use -2 as an indicator only to auto-fit 
-	  non-strings
+	* src/colrow.c (colrow_set_sizes): use -2 as an indicator only to
+	auto-fit non-strings
 	* src/commands.c (cmd_set_text_full): use size -2
-	* src/undo.c (gnm_undo_colrow_set_sizes_new): use -1 and -2 as autofit markers.
+	* src/undo.c (gnm_undo_colrow_set_sizes_new): use -1 and -2 as
+	autofit markers.
 
 2010-08-13  Andreas J. Guelzow <aguelzow pyrshep ca>
 
@@ -29,7 +35,7 @@
 	(cmd_set_text_full): new
 	(cmd_set_text): use cmd_set_text_full
 	(cmd_area_set_text): use cmd_set_text_full
-	
+
 2010-08-12  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* src/commands.c (cmd_area_set_text): use autocorrection
diff --git a/src/commands.c b/src/commands.c
index bd6e534..ab8c7ba 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -787,32 +787,48 @@ cmd_set_text_full (WorkbookControl *wbc, GSList *selection, GnmEvalPos *ep,
 	Sheet *sheet = ep->sheet;
 	GnmParsePos pp;
 	ColRowIndexList *cri_col_list = NULL, *cri_row_list = NULL;
+	GnmCell *cell = NULL;
+	gboolean same_text = FALSE, same_markup = FALSE;
 
 	g_return_val_if_fail (selection != NULL , TRUE);
 
-	/* We should check whether we are in fact changing anything: */
-
-/* 	if (cell) { */
-/* 		char *old_text = gnm_cell_get_entered_text (cell); */
-/* 		same_text = strcmp (old_text, corrected_text) == 0; */
-/* 		g_free (old_text); */
-
-/* 		if (same_text && cell->value && VALUE_IS_STRING (cell->value)) { */
-/* 			const GOFormat *fmt = VALUE_FMT (cell->value); */
-/* 			if (fmt && go_format_is_markup (fmt)) { */
-/* 				const PangoAttrList *old_markup = */
-/* 					go_format_get_markup (fmt); */
-/* 				same_markup = gnm_pango_attr_list_equal 
-				(old_markup, markup); */
-/* 			} */
-/* 		} */
-/* 	} */
-
-/* 	if (same_text && same_markup) { */
-/* 		g_free (corrected_text); */
-/* 		return TRUE; */
-/* 	} */
+	if (go_pango_attr_list_is_empty (markup))
+		markup = NULL;
 
+	/*
+	 * We should check whether we are in fact changing anything.  In order
+	 * to keep it simple, we only try when a single cell is selected.
+	 */
+	if (selection->next == NULL &&
+	    range_is_singleton (selection->data)) {
+		GnmCellPos const *pos = &((GnmRange*)(selection->data))->start;
+		cell = sheet_cell_get (sheet, pos->col, pos->row);
+	}
+
+	if (cell) {
+		const PangoAttrList *old_markup = NULL;
+		char *old_text;
+
+		old_text = gnm_cell_get_entered_text (cell);
+		same_text = strcmp (old_text, new_text) == 0;
+		g_free (old_text);
+
+		if (cell->value && VALUE_IS_STRING (cell->value)) {
+			const GOFormat *fmt = VALUE_FMT (cell->value);
+			if (fmt && go_format_is_markup (fmt)) {
+				old_markup = go_format_get_markup (fmt);
+				if (go_pango_attr_list_is_empty (old_markup))
+					old_markup = NULL;
+			}
+		}
+
+		same_markup = gnm_pango_attr_list_equal (old_markup, markup);
+	}
+
+	if (same_text && same_markup) {
+		range_fragment_free (selection);
+		return TRUE;
+	}
 	
 	parse_pos_init_evalpos (&pp, ep);
 	name = undo_range_list_name (sheet, selection);



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