[gtksourceview/gnome-3-24] view: indent: skip only *completely* empty lines



commit 190037e9a62d25cb2f678b465b8d0715ae4a5355
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Sep 15 19:03:00 2017 +0200

    view: indent: skip only *completely* empty lines
    
    In commit e9f3d760dc6bbb59aae9f8b19716deeeed96e338 (the commit that
    added the indent function in 2006) we can easily see that only
    *completely* empty lines are skipped, so this was the original intent.
    
    And when thinking about it, it makes sense, as the new comment explains
    in the code.
    
    This bug was introduced by
    commit 874a07f0202722607146db39b32f907a2de13b2e in 2007. It doesn't make
    sense to skip lines containing only tabs but not lines containing only
    spaces (or tabs + spaces). 10 years later the bug is reported (and
    fixed).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=787268

 gtksourceview/gtksourceview.c |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)
---
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 47e585a..7846cfb 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -3289,6 +3289,19 @@ gtk_source_view_indent_lines (GtkSourceView *view,
 
                gtk_text_buffer_get_iter_at_line (buf, &iter, i);
 
+               /* Don't add indentation on completely empty lines, to not add
+                * trailing spaces.
+                * Note that non-empty lines containing only whitespaces are
+                * indented like any other non-empty line, because those lines
+                * already contain trailing spaces, some users use those
+                * whitespaces to more easily insert text at the right place
+                * without the need to insert the indentation each time.
+                */
+               if (gtk_text_iter_ends_line (&iter))
+               {
+                       continue;
+               }
+
                /* add spaces always after tabs, to avoid the case
                 * where "\t" becomes "  \t" with no visual difference */
                while (gtk_text_iter_get_char (&iter) == '\t')
@@ -3296,12 +3309,6 @@ gtk_source_view_indent_lines (GtkSourceView *view,
                        gtk_text_iter_forward_char (&iter);
                }
 
-               /* don't add indentation on empty lines */
-               if (gtk_text_iter_ends_line (&iter))
-               {
-                       continue;
-               }
-
                /* if tabs are allowed try to merge the spaces
                 * with the tab we are going to insert (if any) */
                iter2 = iter;


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