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
This commit is contained in:
Christian Hergert
2020-06-29 15:01:26 -07:00
parent bf2d6ab5d6
commit 30b2e1e7a3

View File

@ -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 */