[gtksourceview] Be a bit more smart with the autoindentation.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gtksourceview] Be a bit more smart with the autoindentation.
- Date: Sun, 22 Nov 2009 21:38:13 +0000 (UTC)
commit 186127e1163236b365d658e7121684ccfa16c3c3
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Sun Nov 22 22:36:57 2009 +0100
Be a bit more smart with the autoindentation.
Now when we press enter and the line is empty we remove this line and
we add a new line with the previous indentation. In this way we avoid
trailing spaces.
gtksourceview/gtksourceview.c | 29 +++++++++++++++++++++++++++++
1 files changed, 29 insertions(+), 0 deletions(-)
---
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index c650e22..4a62a4e 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -4033,6 +4033,34 @@ move_lines (GtkTextView *view, gboolean down)
gtk_text_buffer_delete_mark (buf, mark);
}
+static void
+remove_previous_line_if_empty (GtkSourceView *view,
+ GtkTextIter *iter)
+{
+ GtkTextBuffer *buf;
+ GtkTextIter start;
+ gunichar c;
+
+ start = *iter;
+
+ while (TRUE)
+ {
+ gtk_text_iter_backward_char (&start);
+
+ if (gtk_text_iter_starts_line (&start))
+ break;
+
+ c = gtk_text_iter_get_char (&start);
+
+ if (!g_unichar_isspace (c))
+ return;
+ }
+
+ buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+
+ gtk_text_buffer_delete (buf, &start, iter);
+}
+
static gboolean
gtk_source_view_key_press_event (GtkWidget *widget,
GdkEventKey *event)
@@ -4087,6 +4115,7 @@ gtk_source_view_key_press_event (GtkWidget *widget,
/* Insert new line and auto-indent. */
gtk_text_buffer_begin_user_action (buf);
+ remove_previous_line_if_empty (view, &cur);
gtk_text_buffer_insert (buf, &cur, "\n", 1);
gtk_text_buffer_insert (buf, &cur, indent, strlen (indent));
g_free (indent);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]