[gtk/text-scroll-test] textview: Improve scroll-to-mark behavior



commit 67ad566188f7ca80dbf2769ee07fc1bcf14ac511
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Dec 1 19:35:11 2021 -0500

    textview: Improve scroll-to-mark behavior
    
    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 | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index c1b83eb9b3..75f9471c8f 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -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;
         }
     }


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