]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1551: position of marker for 'smoothscroll' not computed correctly v9.0.1551
authorLuuk van Baal <luukvbaal@gmail.com>
Sat, 13 May 2023 13:12:15 +0000 (14:12 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 13 May 2023 13:12:15 +0000 (14:12 +0100)
Problem:    Position of marker for 'smoothscroll' not computed correctly.
Solution:   Take 'list' and other options into account. (Luuk van Baal,
            closes #12393)

src/change.c
src/move.c
src/proto/move.pro
src/testdir/test_scroll_opt.vim
src/version.c

index 8bb61ed1480e956c17bb0669c5b77de049017ab4..c0b8785ba1cc93bad287fe1bfc5cb846cfdfdf90 100644 (file)
@@ -568,8 +568,8 @@ changed_common(
                            && wp->w_topline < lnume
                            && win_linetabsize(wp, wp->w_topline,
                                        ml_get(wp->w_topline), (colnr_T)MAXCOL)
-                                   <= wp->w_skipcol + (wp->w_p_list
-                                           && wp->w_lcs_chars.prec ? 1 : 3))))
+                                   <= wp->w_skipcol + sms_marker_overlap(wp,
+                                       win_col_off(wp) - win_col_off2(wp)))))
                wp->w_skipcol = 0;
 
            // Check if a change in the buffer has invalidated the cached
index 877560792a23bfc10e39939d30a9682442fae475..d969de2fc030ed9a2dae225d368aa09f28c9dcf6 100644 (file)
@@ -202,22 +202,26 @@ redraw_for_cursorcolumn(win_T *wp)
 #endif
 
 /*
- * Calculates how much overlap the smoothscroll marker "<<<" overlaps with
- * buffer text for curwin.
+ * Calculates how much the 'listchars' "precedes" or 'smoothscroll' "<<<"
+ * marker overlaps with buffer text for window "wp".
  * Parameter "extra2" should be the padding on the 2nd line, not the first
  * line.
  * Returns the number of columns of overlap with buffer text, excluding the
  * extra padding on the ledge.
  */
-    static int
-smoothscroll_marker_overlap(int extra2)
+     int
+sms_marker_overlap(win_T *wp, int extra2)
 {
 #if defined(FEAT_LINEBREAK)
-    // We don't draw the <<< marker when in showbreak mode, thus no need to
+    // There is no marker overlap when in showbreak mode, thus no need to
     // account for it.  See wlv_screen_line().
-    if (*get_showbreak_value(curwin) != NUL)
+    if (*get_showbreak_value(wp) != NUL)
        return 0;
 #endif
+    // Overlap when 'list' and 'listchars' "precedes" are set is 1.
+    if (wp->w_p_list && wp->w_lcs_chars.prec)
+       return 1;
+
     return extra2 > 3 ? 0 : 3 - extra2;
 }
 
@@ -346,12 +350,11 @@ update_topline(void)
                colnr_T vcol;
 
                // Check that the cursor position is visible.  Add columns for
-               // the smoothscroll marker "<<<" displayed in the top-left if
-               // needed.
+               // the marker displayed in the top-left if needed.
                getvvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
-               int smoothscroll_overlap = smoothscroll_marker_overlap(
-                                        curwin_col_off() - curwin_col_off2());
-               if (curwin->w_skipcol + smoothscroll_overlap > vcol)
+               int overlap = sms_marker_overlap(curwin, curwin_col_off()
+                                                       - curwin_col_off2());
+               if (curwin->w_skipcol + overlap > vcol)
                    check_topline = TRUE;
            }
        }
@@ -1883,10 +1886,10 @@ scrollup(
        int     scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2;
        int     space_cols = (curwin->w_height - 1) * width2;
 
-       // If we have non-zero scrolloff, just ignore the <<< marker as we are
+       // If we have non-zero scrolloff, just ignore the marker as we are
        // going past it anyway.
-       int smoothscroll_overlap = scrolloff_cols != 0 ? 0 :
-                                          smoothscroll_marker_overlap(extra2);
+       int overlap = scrolloff_cols != 0 ? 0
+                                         : sms_marker_overlap(curwin, extra2);
 
        // Make sure the cursor is in a visible part of the line, taking
        // 'scrolloff' into account, but using screen lines.
@@ -1894,15 +1897,13 @@ scrollup(
        if (scrolloff_cols > space_cols / 2)
            scrolloff_cols = space_cols / 2;
        validate_virtcol();
-       if (curwin->w_virtcol < curwin->w_skipcol
-                                      + smoothscroll_overlap + scrolloff_cols)
+       if (curwin->w_virtcol < curwin->w_skipcol + overlap + scrolloff_cols)
        {
            colnr_T col = curwin->w_virtcol;
 
            if (col < width1)
                col += width1;
-           while (col < curwin->w_skipcol
-                                      + smoothscroll_overlap + scrolloff_cols)
+           while (col < curwin->w_skipcol + overlap + scrolloff_cols)
                col += width2;
            curwin->w_curswant = col;
            coladvance(curwin->w_curswant);
@@ -1949,8 +1950,10 @@ adjust_skipcol(void)
     }
 
     validate_virtcol();
+    int overlap = sms_marker_overlap(curwin,
+                                        curwin_col_off() - curwin_col_off2());
     while (curwin->w_skipcol > 0
-                && curwin->w_virtcol < curwin->w_skipcol + 3 + scrolloff_cols)
+           && curwin->w_virtcol < curwin->w_skipcol + overlap + scrolloff_cols)
     {
        // scroll a screen line down
        if (curwin->w_skipcol >= width1 + width2)
index 1fe46a34105a46fd24ad73c53f4da8185d3a8233..75f15444dd468840c303baf19e39b023de90350e 100644 (file)
@@ -1,6 +1,7 @@
 /* move.c */
 int adjust_plines_for_skipcol(win_T *wp, int n);
 void redraw_for_cursorline(win_T *wp);
+int sms_marker_overlap(win_T *wp, int extra2);
 void update_topline_redraw(void);
 void update_topline(void);
 void update_curswant_force(void);
index 0bdf6840b944e451c0d1741857b32072529b15f2..636e7b76c50bf24c5de98aaa3c5e7744907d106a 100644 (file)
@@ -426,8 +426,7 @@ func Test_smoothscroll_cursor_position()
 
   " Test moving the cursor behind the <<< display with 'virtualedit'
   set virtualedit=all
-  exe "normal \<C-E>"
-  norm 3lgkh
+  exe "normal \<C-E>3lgkh"
   call s:check_col_calc(3, 2, 23)
   set virtualedit&
 
@@ -499,6 +498,16 @@ func Test_smoothscroll_cursor_position()
   call s:check_col_calc(1, 3, 37)
   normal gg
 
+  " Test list + listchars "precedes", where there is always 1 overlap
+  " regardless of number and cpo-=n.
+  setl number list listchars=precedes:< cpo-=n
+  call s:check_col_calc(5, 1, 1)
+  exe "normal 2|\<C-E>"
+  call s:check_col_calc(6, 1, 18)
+  norm h
+  call s:check_col_calc(5, 2, 17)
+  normal gg
+
   bwipe!
 endfunc
 
index 923ea9794ca36fc694669881f0449f78c6391f7a..cc7c4e1ce45663bff4212923596eeb72e88cc48f 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1551,
 /**/
     1550,
 /**/