diff options
author | Christian Hergert <chergert@redhat.com> | 2020-06-29 15:01:26 -0700 |
---|---|---|
committer | Christian Hergert <chergert@redhat.com> | 2020-06-29 15:07:59 -0700 |
commit | 30b2e1e7a36a59c19ad2475f31ef4baf2dcd1e8c (patch) | |
tree | cf6d11cd706229615c802d6d4c915966145797dd /gtk | |
parent | bf2d6ab5d61ec1eea78605ea706f09050717d761 (diff) | |
download | gtk+-30b2e1e7a36a59c19ad2475f31ef4baf2dcd1e8c.tar.gz |
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
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtktextview.c | 18 |
1 files changed, 18 insertions, 0 deletions
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 */ |