textview: fix textview drawing in presence of gutters
authorChristian Hergert <chergert@redhat.com>
Fri, 13 Sep 2019 23:02:28 +0000 (16:02 -0700)
committerChristian Hergert <chergert@redhat.com>
Fri, 13 Sep 2019 23:02:28 +0000 (16:02 -0700)
When drawing a left or top gutter, we need to adjust the origin of the
text snapshot or we risk the gutter drawing above the text.

gtk/gtktextview.c

index c9657cef102f782b63012697f9efe58462f861b1..4568e735feffb8c5aa2aa7e1236d8bd1a48c8dfc 100644 (file)
@@ -5390,6 +5390,18 @@ draw_text (GtkWidget   *widget,
   GtkTextView *text_view = GTK_TEXT_VIEW (widget);
   GtkTextViewPrivate *priv = text_view->priv;
   GtkStyleContext *context;
+  graphene_point_t translate = {0};
+
+  if (priv->left_window)
+    translate.x = priv->left_window->allocation.width;
+  if (priv->top_window)
+    translate.y = priv->top_window->allocation.height;
+
+  if (translate.x || translate.y)
+    {
+      gtk_snapshot_save (snapshot);
+      gtk_snapshot_translate (snapshot, &translate);
+    }
 
   context = gtk_widget_get_style_context (widget);
   gtk_style_context_save_to_node (context, text_view->priv->text_window->css_node);
@@ -5420,6 +5432,9 @@ draw_text (GtkWidget   *widget,
       GTK_TEXT_VIEW_GET_CLASS (text_view)->snapshot_layer (text_view, GTK_TEXT_VIEW_LAYER_ABOVE_TEXT, snapshot);
       gtk_snapshot_restore (snapshot);
     }
+
+  if (translate.x || translate.y)
+    gtk_snapshot_restore (snapshot);
 }
 
 static void