[gtk/wip/chergert/fix-gtk3-textview-pixelcache] textview: invalidate pixelcache for some invisible changes



commit 30b2e1e7a36a59c19ad2475f31ef4baf2dcd1e8c
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jun 29 15:01:26 2020 -0700

    textview: invalidate pixelcache for some invisible changes
    
    When making changes above the current visible region, we might need to
    invalidate the pixelcache as the Y positions will no longer match. This
    usually is not needed because changes are made interactively and are made
    onscreen.
    
    Other cases, though, can include an application changing the first line
    of the buffer automatically. We lose the ability to pixelcache well in
    this scenario, but that is unlikely an issue since rapid Y geometry resize
    or scrolling is less likely to be occuring. For situations where this is
    an issue, you can avoid removing the \n from the buffer so line heights
    are uneffected.
    
    Fixes #2882

 gtk/gtktextview.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
---
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 408129bfef..a1c0bfce83 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -4668,6 +4668,24 @@ changed_handler (GtkTextLayout     *layout,
           priv->yoffset += new_first_para_top - old_first_para_top;
           
           gtk_adjustment_set_value (text_view->priv->vadjustment, priv->yoffset);
+
+          /* If the height changed above our current position, then we
+           * need to discard the pixelcache because things wont line nup
+           * anymore (even if we adjust the vadjustment).
+           *
+           * Generally this doesn't happen interactively because we keep
+           * the insert cursor on screen when making changes. It can
+           * happen when code changes the first line, for example, in an
+           * automated fashion.
+           *
+           * There is one case where this could be optimized out such as
+           * when delete-range is followed by insert-text and whole lines
+           * are removed. API consumers can always work around that by
+           * avoiding the removal of a \n so no effort is made here to
+           * handle that.
+           */
+          if (gtk_widget_get_realized (widget))
+            _gtk_pixel_cache_invalidate (text_view->priv->pixel_cache, NULL);
         }
 
       /* FIXME be smarter about which anchored widgets we update */


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