[gnome-builder] buffer: only treat space (' ') and tab ('\t') as trimmable
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] buffer: only treat space (' ') and tab ('\t') as trimmable
- Date: Fri, 16 Oct 2015 18:02:22 +0000 (UTC)
commit eea3027a4db73fd123864e14d569f7dd4ce82861
Author: Christian Hergert <christian hergert me>
Date: Fri Oct 16 11:02:06 2015 -0700
buffer: only treat space (' ') and tab ('\t') as trimmable
We want to avoid trimming whitespace that could be inserted on purpose.
Various GNU projects use linefeed/formfeed characters.
https://bugzilla.gnome.org/show_bug.cgi?id=756705
libide/ide-buffer.c | 18 +++++++++++++++---
1 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/libide/ide-buffer.c b/libide/ide-buffer.c
index 0ecbdd1..00ee4b1 100644
--- a/libide/ide-buffer.c
+++ b/libide/ide-buffer.c
@@ -55,8 +55,6 @@
#define TAG_DEPRECATED "diagnostician::deprecated"
#define TAG_NOTE "diagnostician::note"
-#define TEXT_ITER_IS_SPACE(ptr) g_unichar_isspace(gtk_text_iter_get_char(ptr))
-
typedef struct
{
IdeContext *context;
@@ -1670,8 +1668,10 @@ ide_buffer_get_content (IdeBuffer *self)
return g_bytes_ref (priv->content);
}
+
+
void
-ide_buffer_trim_trailing_whitespace (IdeBuffer *self)
+ide_buffer_trim_trailing_whitespace (IdeBuffer *self)
{
IdeBufferPrivate *priv = ide_buffer_get_instance_private (self);
GtkTextBuffer *buffer;
@@ -1700,6 +1700,16 @@ ide_buffer_trim_trailing_whitespace (IdeBuffer *self)
{
gtk_text_buffer_get_iter_at_line (buffer, &iter, line);
+/*
+ * Preserve all whitespace that isn't space or tab.
+ * This could include line feed, form feed, etc.
+ */
+#define TEXT_ITER_IS_SPACE(ptr) \
+ ({ \
+ gunichar ch = gtk_text_iter_get_char (ptr); \
+ (ch == ' ' || ch == '\t'); \
+ })
+
if (gtk_text_iter_forward_to_line_end (&iter) && TEXT_ITER_IS_SPACE (&iter))
{
GtkTextIter begin = iter;
@@ -1719,6 +1729,8 @@ ide_buffer_trim_trailing_whitespace (IdeBuffer *self)
if (!gtk_text_iter_equal (&begin, &iter))
gtk_text_buffer_delete (buffer, &begin, &iter);
}
+
+#undef TEXT_ITER_IS_SPACE
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]