[gtksourceview/wip/improve-gutter-perfs] RendererLines: compare last visible line



commit 7d42de6b8cb281940b0abb54638e6cecab09af5b
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Sep 15 17:03:27 2014 +0200

    RendererLines: compare last visible line

 gtksourceview/gtksourcegutterrendererlines.c |   31 +++++++++++++++++++++----
 1 files changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/gtksourceview/gtksourcegutterrendererlines.c b/gtksourceview/gtksourcegutterrendererlines.c
index 5670dba..e7c23a7 100644
--- a/gtksourceview/gtksourcegutterrendererlines.c
+++ b/gtksourceview/gtksourcegutterrendererlines.c
@@ -25,7 +25,7 @@
 struct _GtkSourceGutterRendererLinesPrivate
 {
        gint num_line_digits;
-       gint prev_line_count;
+       gint prev_line_num;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceGutterRendererLines, gtk_source_gutter_renderer_lines, 
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT)
@@ -119,7 +119,7 @@ gutter_renderer_change_buffer (GtkSourceGutterRenderer *renderer,
                recalculate_size (lines);
        }
 
-       lines->priv->prev_line_count = 0;
+       lines->priv->prev_line_num = 0;
 }
 
 static void
@@ -191,6 +191,27 @@ gutter_renderer_query_data (GtkSourceGutterRenderer      *renderer,
        g_free (text);
 }
 
+static gint
+get_last_visible_line_number (GtkSourceGutterRendererLines *lines)
+{
+       GtkTextView *view;
+       GdkRectangle visible_rect;
+       GtkTextIter iter;
+
+       view = gtk_source_gutter_renderer_get_view (GTK_SOURCE_GUTTER_RENDERER (lines));
+
+       gtk_text_view_get_visible_rect (view, &visible_rect);
+
+       gtk_text_view_get_line_at_y (view,
+                                    &iter,
+                                    visible_rect.y + visible_rect.height,
+                                    NULL);
+
+       gtk_text_iter_forward_line (&iter);
+
+       return gtk_text_iter_get_line (&iter);
+}
+
 static void
 gutter_renderer_end (GtkSourceGutterRenderer *renderer)
 {
@@ -199,7 +220,7 @@ gutter_renderer_end (GtkSourceGutterRenderer *renderer)
 
        if (buffer != NULL)
        {
-               gint line_count = gtk_text_buffer_get_line_count (buffer);
+               gint line_num = get_last_visible_line_number (lines);
 
                /* When the text is modified in a GtkTextBuffer, GtkTextView tries to
                 * redraw the smallest required region. But the information displayed in
@@ -224,9 +245,9 @@ gutter_renderer_end (GtkSourceGutterRenderer *renderer)
                 * have padding for future expansion, so it must wait for
                 * GtkSourceView 4.
                 */
-               if (lines->priv->prev_line_count != line_count)
+               if (lines->priv->prev_line_num != line_num)
                {
-                       lines->priv->prev_line_count = line_count;
+                       lines->priv->prev_line_num = line_num;
                        gtk_source_gutter_renderer_queue_draw (renderer);
                }
        }


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