textview: Improve scroll-to-mark behavior
authorMatthias Clasen <mclasen@redhat.com>
Thu, 2 Dec 2021 00:35:11 +0000 (19:35 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 2 Dec 2021 00:35:11 +0000 (19:35 -0500)
The idea of within-margin is to scroll as little
as possible to bring the mark within the margins
defined by the factor. The code was achieving
that when scrolling down, but not when scrolling
up. This change makes things symmetrical.

Fixes: #4325
gtk/gtktextview.c

index c1b83eb9b38e24c767c78c67c0e9279791a5e651..75f9471c8f3352bdb5db251f35ec53acd4c64e96 100644 (file)
@@ -2641,16 +2641,16 @@ _gtk_text_view_scroll_to_iter (GtkTextView   *text_view,
       if (cursor.y < screen_inner_top)
         {
           if (cursor.y == 0)
-            border_yoffset = (with_border) ? priv->top_padding : 0;
+            border_yoffset = with_border ? priv->top_padding : 0;
 
           screen_dest.y = cursor.y - MAX (within_margin_yoffset, border_yoffset);
         }
       else if (cursor_bottom > screen_inner_bottom)
         {
           if (cursor_bottom == buffer_bottom - priv->top_margin)
-            border_yoffset = (with_border) ? priv->bottom_padding : 0;
+            border_yoffset = with_border ? priv->bottom_padding : 0;
 
-          screen_dest.y = cursor_bottom - screen_dest.height +
+          screen_dest.y = cursor_bottom - screen_dest.height -
                           MAX (within_margin_yoffset, border_yoffset);
         }
     }
@@ -2679,16 +2679,16 @@ _gtk_text_view_scroll_to_iter (GtkTextView   *text_view,
       if (cursor.x < screen_inner_left)
         {
           if (cursor.x == priv->left_margin)
-            border_xoffset = (with_border) ? priv->left_padding : 0;
+            border_xoffset = with_border ? priv->left_padding : 0;
 
           screen_dest.x = cursor.x - MAX (within_margin_xoffset, border_xoffset);
         }
       else if (cursor_right >= screen_inner_right - 1)
         {
           if (cursor.x >= buffer_right - priv->right_padding)
-            border_xoffset = (with_border) ? priv->right_padding : 0;
+            border_xoffset = with_border ? priv->right_padding : 0;
 
-          screen_dest.x = cursor_right - screen_dest.width +
+          screen_dest.x = cursor_right - screen_dest.width -
                           MAX (within_margin_xoffset, border_xoffset) + 1;
         }
     }