[gnome-text-editor] sourceview: fix line spacing



commit 9925a8f4aef860d3f9381be585cfdc1f4ed1f40f
Author: Christian Hergert <chergert redhat com>
Date:   Tue Oct 12 13:06:55 2021 -0700

    sourceview: fix line spacing
    
    Originally we had line spacing and it got lost along the way with all the
    text buffer changes and CSS changes. This uses a better approach in that
    it is part of the CSS generated for the text view directly.
    
    Our original spacing was supposed to be around 1.5x line height, so this
    restores that.
    
    The benefit of doing this here without using text tags is that it doesn't
    affect the overview map nor does it require adjusting text tags on every
    change to the underlying buffer.

 src/editor-source-view.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
---
diff --git a/src/editor-source-view.c b/src/editor-source-view.c
index b65c442..0d45f17 100644
--- a/src/editor-source-view.c
+++ b/src/editor-source-view.c
@@ -57,12 +57,6 @@ editor_source_view_update_css (EditorSourceView *self)
 
   g_assert (EDITOR_IS_SOURCE_VIEW (self));
 
-  if (self->font_scale == 0 && self->font_desc == NULL)
-    {
-      gtk_css_provider_load_from_data (self->css_provider, "", -1);
-      return;
-    }
-
   if (self->font_desc != NULL &&
       pango_font_description_get_set_fields (self->font_desc) & PANGO_FONT_MASK_SIZE)
     size = pango_font_description_get_size (self->font_desc) / PANGO_SCALE;
@@ -87,7 +81,7 @@ editor_source_view_update_css (EditorSourceView *self)
 
       font_css = _editor_font_description_to_css (font_desc);
       g_string_append (str, font_css);
-      g_string_append_c (str, '\n');
+      g_string_append (str, "\nline-height:150%;\n");
     }
   g_string_append (str, "}\n");
 
@@ -348,6 +342,16 @@ editor_source_view_action_zoom (GtkWidget  *widget,
   editor_source_view_update_css (self);
 }
 
+static void
+editor_source_view_constructed (GObject *object)
+{
+  EditorSourceView *self = (EditorSourceView *)object;
+
+  G_OBJECT_CLASS (editor_source_view_parent_class)->constructed (object);
+
+  editor_source_view_update_css (self);
+}
+
 static void
 editor_source_view_finalize (GObject *object)
 {
@@ -404,6 +408,7 @@ editor_source_view_class_init (EditorSourceViewClass *klass)
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
+  object_class->constructed = editor_source_view_constructed;
   object_class->finalize = editor_source_view_finalize;
   object_class->get_property = editor_source_view_get_property;
   object_class->set_property = editor_source_view_set_property;


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