[gnome-builder] c-pack: improve indenter handling of prefix spacing
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] c-pack: improve indenter handling of prefix spacing
- Date: Fri, 22 Jun 2018 19:23:49 +0000 (UTC)
commit af02fe9b2760afe83ff1a0f5b4f4e0d6be8c93e7
Author: Christian Hergert <chergert redhat com>
Date: Fri Jun 22 12:20:00 2018 -0700
c-pack: improve indenter handling of prefix spacing
If we indent a new line, and that line has trailing whitespace, we should
consume it so that the text starts immediately after the inserted indent
string.
Fixes #545
src/plugins/c-pack/ide-c-indenter.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/c-pack/ide-c-indenter.c b/src/plugins/c-pack/ide-c-indenter.c
index c8c011298..5b17cdaeb 100644
--- a/src/plugins/c-pack/ide-c-indenter.c
+++ b/src/plugins/c-pack/ide-c-indenter.c
@@ -60,6 +60,13 @@ enum {
COMMENT_C99
};
+static inline gboolean
+text_iter_isspace (const GtkTextIter *iter)
+{
+ gunichar ch = gtk_text_iter_get_char (iter);
+ return g_unichar_isspace (ch);
+}
+
static inline guint
get_post_scope_indent (IdeCIndenter *c)
{
@@ -1345,9 +1352,22 @@ ide_c_indenter_format (IdeIndenter *indenter,
switch (event->keyval) {
case GDK_KEY_Return:
case GDK_KEY_KP_Enter:
- gtk_text_iter_assign (&begin_copy, begin);
+ begin_copy = *begin;
ret = c_indenter_indent (c, view, buffer, begin);
- gtk_text_iter_assign (begin, &begin_copy);
+ *begin = begin_copy;
+
+ if (!dzl_str_empty0 (ret))
+ {
+ /*
+ * If we have additional space after where our new indentation
+ * will occur, we should chomp it up so that the text starts
+ * immediately after our new indentation.
+ *
+ * GNOME/gnome-builder#545
+ */
+ while (text_iter_isspace (end) && !gtk_text_iter_ends_line (end))
+ gtk_text_iter_forward_char (end);
+ }
/*
* If we are inserting a newline right before a closing brace (for example
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]