[gtksourceview/gnome-2-30] Fix trailing/leading space determination



commit 95d391fbb418a5218ebeb2ea4bffcd1c71788002
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Mon May 10 14:15:01 2010 +0200

    Fix trailing/leading space determination

 gtksourceview/gtksourceview.c |   22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)
---
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 13c4b5e..dab5868 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -2480,7 +2480,9 @@ get_leading_trailing (GtkTextIter *iter,
 	{
 		gunichar ch = gtk_text_iter_get_char (&start);
 
-		if (!g_unichar_isspace (ch) ||
+		/* NOTE: ch can be 0 when iter is at the end
+		   of the buffer */
+		if (!(g_unichar_isspace (ch) || ch == 0) ||
 		     gtk_text_iter_starts_line (&start) ||
 		    !gtk_text_iter_backward_char (&start))
 		{
@@ -2496,6 +2498,7 @@ check_location (GtkSourceView *view,
                 GtkTextIter   *leading,
                 GtkTextIter   *trailing)
 {
+	gint flags = 0;
 	gint location = view->priv->draw_spaces & (GTK_SOURCE_DRAW_SPACES_LEADING |
 	                                           GTK_SOURCE_DRAW_SPACES_TEXT |
 	                                           GTK_SOURCE_DRAW_SPACES_TRAILING);
@@ -2506,20 +2509,25 @@ check_location (GtkSourceView *view,
 		return TRUE;
 	}
 
-	/* If leading > trailing we are in an empty line so we paint also
-	   for leading spaces */
 	if (gtk_text_iter_compare (iter, trailing) >= 0)
 	{
-		return location & (GTK_SOURCE_DRAW_SPACES_TRAILING |
-				   GTK_SOURCE_DRAW_SPACES_LEADING);
+		flags |= GTK_SOURCE_DRAW_SPACES_TRAILING;
 	}
 
 	if (gtk_text_iter_compare (iter, leading) < 0)
 	{
-		return location & GTK_SOURCE_DRAW_SPACES_LEADING;
+		flags |= GTK_SOURCE_DRAW_SPACES_LEADING;
 	}
 
-	return location & GTK_SOURCE_DRAW_SPACES_TEXT;
+	if (flags == 0)
+	{
+		/* Neither leading nor trailing, must be in text */
+		return location & GTK_SOURCE_DRAW_SPACES_TEXT;
+	}
+	else
+	{
+		return location & flags;
+	}
 }
 static void
 draw_tabs_and_spaces (GtkSourceView  *view,



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