patch 9.1.0380: Calculating line height for unnecessary amount of lines

Commit: 
https://github.com/vim/vim/commit/32d701f51b1ed2834071a2c5031a300936beda13
Author: Luuk van Baal <luukvb...@gmail.com>
Date:   Sun Apr 28 16:24:02 2024 +0200

    patch 9.1.0380: Calculating line height for unnecessary amount of lines
    
    Problem:  Calculating line height for unnecessary amount of lines with
              half-page scrolling (zhscn, after 9.1.0280)
    Solution: Replace "limit_winheight" argument with higher resolution
              "max" argument to which to limit the calculated line height
              in plines_m_win() to (Luuk van Baal)
    
    fixes: #14650
    closes: #14652
    
    Signed-off-by: Luuk van Baal <luukvb...@gmail.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/drawscreen.c b/src/drawscreen.c
index f8818ff1a..9096c28df 100644
--- a/src/drawscreen.c
+++ b/src/drawscreen.c
@@ -1781,7 +1781,7 @@ win_update(win_T *wp)
            if (j < wp->w_height - 2)           // not too far off
            {
                i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1,
-                                                                        TRUE);
+                                                               wp->w_height);
 #ifdef FEAT_DIFF
                // insert extra lines for previously invisible filler lines
                if (wp->w_lines[0].wl_lnum != wp->w_topline)
diff --git a/src/misc1.c b/src/misc1.c
index c5a0c3852..834848886 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -497,12 +497,17 @@ plines_win_col(win_T *wp, linenr_T lnum, long column)
     return lines;
 }
 
+/*
+ * Return number of window lines the physical line range from "first" until
+ * "last" will occupy in window "wp". Takes into account folding, 'wrap',
+ * topfill and filler lines beyond the end of the buffer. Limit to "max" lines.
+ */
     int
-plines_m_win(win_T *wp, linenr_T first, linenr_T last, int limit_winheight)
+plines_m_win(win_T *wp, linenr_T first, linenr_T last, int max)
 {
     int                count = 0;
 
-    while (first <= last && (!limit_winheight || count < wp->w_height))
+    while (first <= last && count < max)
     {
 #ifdef FEAT_FOLDING
        int     x;
@@ -531,9 +536,7 @@ plines_m_win(win_T *wp, linenr_T first, linenr_T last, int 
limit_winheight)
     if (first == wp->w_buffer->b_ml.ml_line_count + 1)
        count += diff_check_fill(wp, first);
 #endif
-    if (limit_winheight && count > wp->w_height)
-       return wp->w_height;
-    return (count);
+    return MIN(max, count);
 }
 
     int
diff --git a/src/move.c b/src/move.c
index 1b6e003cc..9bdd46f2c 100644
--- a/src/move.c
+++ b/src/move.c
@@ -1455,7 +1455,7 @@ textpos2screenpos(
 
        is_folded = hasFoldingWin(wp, lnum, &lnum, NULL, TRUE, NULL);
 #endif
-       row = plines_m_win(wp, wp->w_topline, lnum - 1, FALSE);
+       row = plines_m_win(wp, wp->w_topline, lnum - 1, INT_MAX);
        // "row" should be the screen line where line "lnum" begins, which can
        // be negative if "lnum" is "w_topline" and "w_skipcol" is non-zero.
        row -= adjust_plines_for_skipcol(wp);
@@ -3219,12 +3219,18 @@ pagescroll(int dir, long count, int half)
 
        int curscount = count;
        // Adjust count so as to not reveal end of buffer lines.
-       if (dir == FORWARD)
+       if (dir == FORWARD
+                   && (curwin->w_topline + curwin->w_height + count > buflen
+#ifdef FEAT_FOLDING
+                                                       || hasAnyFolding(curwin)
+#endif
+          ))
        {
            int n = plines_correct_topline(curwin, curwin->w_topline, FALSE);
            if (n - count < curwin->w_height && curwin->w_topline < buflen)
-               n += plines_m_win(curwin, curwin->w_topline + 1, buflen, FALSE);
-           if (n - count < curwin->w_height)
+               n += plines_m_win(curwin, curwin->w_topline + 1, buflen,
+                                                   curwin->w_height + count);
+           if (n < curwin->w_height + count)
                count = n - curwin->w_height;
        }
 
diff --git a/src/popupwin.c b/src/popupwin.c
index 25bb15349..38c1c9e0d 100644
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -654,8 +654,8 @@ popup_show_curline(win_T *wp)
            wp->w_topline = wp->w_buffer->b_ml.ml_line_count;
        while (wp->w_topline < wp->w_cursor.lnum
                && wp->w_topline < wp->w_buffer->b_ml.ml_line_count
-               && plines_m_win(wp, wp->w_topline, wp->w_cursor.lnum, FALSE)
-                                                               > wp->w_height)
+               && plines_m_win(wp, wp->w_topline, wp->w_cursor.lnum,
+                                           wp->w_height + 1) > wp->w_height)
            ++wp->w_topline;
     }
 
diff --git a/src/proto/misc1.pro b/src/proto/misc1.pro
index e76bf75d0..d64f961f0 100644
--- a/src/proto/misc1.pro
+++ b/src/proto/misc1.pro
@@ -7,7 +7,7 @@ int plines_nofill(linenr_T lnum);
 int plines_win_nofill(win_T *wp, linenr_T lnum, int limit_winheight);
 int plines_win_nofold(win_T *wp, linenr_T lnum);
 int plines_win_col(win_T *wp, linenr_T lnum, long column);
-int plines_m_win(win_T *wp, linenr_T first, linenr_T last, int 
limit_winheight);
+int plines_m_win(win_T *wp, linenr_T first, linenr_T last, int max);
 int gchar_pos(pos_T *pos);
 int gchar_cursor(void);
 void pchar_cursor(int c);
diff --git a/src/version.c b/src/version.c
index 0f665efd6..107039fad 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    380,
 /**/
     379,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1s15Xg-002h5J-3d%40256bit.org.

Raspunde prin e-mail lui