[gtksourceview] gutterlines: improve positioning of lines



commit dbecf1e22a249b57e32d87de1ed4290a9a3ec015
Author: Christian Hergert <chergert redhat com>
Date:   Tue Oct 19 14:20:15 2021 -0700

    gutterlines: improve positioning of lines
    
    If we have line positions that could be set on the first or last line,
    then we need to use some heuristics to try to remove line-height
    alterations. Doing so improves our chances of placing the line number
    aligned with the line text.

 gtksourceview/gtksourcegutterlines.c | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)
---
diff --git a/gtksourceview/gtksourcegutterlines.c b/gtksourceview/gtksourcegutterlines.c
index 17aa595e..70e209d6 100644
--- a/gtksourceview/gtksourcegutterlines.c
+++ b/gtksourceview/gtksourcegutterlines.c
@@ -209,11 +209,14 @@ _gtk_source_gutter_lines_new (GtkTextView       *text_view,
 
                                if (needs_wrap_first)
                                {
-
-                                       gtk_text_view_get_iter_location (text_view,
-                                                                        &iter,
-                                                                        &rect);
+                                       gtk_text_view_get_iter_location (text_view, &iter, &rect);
                                        info.first_height = rect.height;
+
+                                       if (info.y != rect.y)
+                                       {
+                                               info.height -= rect.y - info.y;
+                                               info.y = rect.y;
+                                       }
                                }
                                else
                                {
@@ -223,14 +226,27 @@ _gtk_source_gutter_lines_new (GtkTextView       *text_view,
                                if (needs_wrap_last)
                                {
                                        gtk_text_iter_forward_to_line_end (&iter);
-                                       gtk_text_view_get_iter_location (text_view,
-                                                                        &iter,
-                                                                        &rect);
+
+                                       /* Prefer the character right before \n to get
+                                        * more accurate rectangle sizing.
+                                        */
+                                       if (!gtk_text_iter_starts_line (&iter))
+                                       {
+                                               gtk_text_iter_backward_char (&iter);
+                                               gtk_text_view_get_iter_location (text_view, &iter, &rect);
+                                               gtk_text_iter_forward_char (&iter);
+                                       }
+                                       else
+                                       {
+                                               gtk_text_view_get_iter_location (text_view, &iter, &rect);
+                                       }
+
                                        info.last_height = rect.height;
+                                       info.height = rect.y + rect.height - info.y;
                                }
                                else
                                {
-                                       info.last_height = info.height;
+                                       info.last_height = info.first_height;
                                }
                        }
                }


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