[gnome-builder/wip/commands2] change-monitor: add trailing newline if necessary



commit 3381c3b26638943cfe1cf065f5768153d2d09c6e
Author: Christian Hergert <christian hergert me>
Date:   Thu Oct 9 15:20:16 2014 -0700

    change-monitor: add trailing newline if necessary
    
    GtkSourceBuffer has a feature called implicit-trailing-newline that
    will automatically hide the trailing newline from documents. This is
    especially useful in .c or .h documents. However, it breaks the change
    monitor making it think the trailing newline has been removed.
    
    This simply adds that newline back to the document to its original form
    if that feature is enabled.

 src/editor/gb-source-change-monitor.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/src/editor/gb-source-change-monitor.c b/src/editor/gb-source-change-monitor.c
index 4e1a7f3..6ffe7a1 100644
--- a/src/editor/gb-source-change-monitor.c
+++ b/src/editor/gb-source-change-monitor.c
@@ -213,6 +213,7 @@ on_parse_timeout (GbSourceChangeMonitor *monitor)
 {
   GbSourceChangeMonitorPrivate *priv;
   GSimpleAsyncResult *async;
+  GtkSourceBuffer *gsb;
   GtkTextIter begin;
   GtkTextIter end;
   gchar *text = NULL;
@@ -246,6 +247,18 @@ on_parse_timeout (GbSourceChangeMonitor *monitor)
   text = gtk_text_buffer_get_text (priv->buffer, &begin, &end, TRUE);
 
   /*
+   * If the buffer has the trailing newline hidden, go ahead and add one back.
+   */
+  gsb = GTK_SOURCE_BUFFER (priv->buffer);
+  if (gtk_source_buffer_get_implicit_trailing_newline (gsb))
+    {
+      gchar *tmp = text;
+
+      text = g_strconcat (text, "\n", NULL);
+      g_free (tmp);
+    }
+
+  /*
    * Set the required fields for our worker.
    */
   g_object_set_data_full (G_OBJECT (async), "text", text, g_free);


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