[gtksourceview] view: indent: skip only *completely* empty lines
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] view: indent: skip only *completely* empty lines
- Date: Fri, 15 Sep 2017 17:20:54 +0000 (UTC)
commit 9c7f94579e7605c2b6188a3e52c65b1e168195d2
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 4d6efb3..005529a 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -3235,6 +3235,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')
@@ -3242,12 +3255,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]