]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0285: Still problems with cursor position for CTRL-D/U v9.1.0285
authorLuuk van Baal <luukvbaal@gmail.com>
Tue, 9 Apr 2024 19:30:19 +0000 (21:30 +0200)
committerChristian Brabandt <cb@256bit.org>
Tue, 9 Apr 2024 19:30:19 +0000 (21:30 +0200)
Problem:  Problems with cursor position when scrolling half a page.
Solution: Rework the cursor logic. (Luuk van Baal)

closes: #14455

Signed-off-by: Luuk van Baal <luukvbaal@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/move.c
src/testdir/test_normal.vim
src/testdir/test_scroll_opt.vim
src/version.c

index 0bf59c9f90672b0fcfcebb2de9e75daadc1b9cc4..9853b0b8dadf235fe75e62d4c302a451ffbc7553 100644 (file)
@@ -3165,7 +3165,6 @@ static int scroll_with_sms(int dir, long count)
        // extra for scrolling backward so that consuming skipcol is symmetric.
        if (labs(curwin->w_topline - prev_topline) > (dir == BACKWARD))
            fixdir = dir * -1;
-       validate_cursor();
        while (curwin->w_skipcol > 0
            && curwin->w_topline < curbuf->b_ml.ml_line_count)
            scroll_redraw(fixdir == FORWARD, 1);
@@ -3192,6 +3191,7 @@ pagescroll(int dir, long count, int half)
     int                nochange = TRUE;
     int                buflen = curbuf->b_ml.ml_line_count;
     colnr_T    prev_col = curwin->w_cursor.col;
+    colnr_T    prev_curswant = curwin->w_curswant;
     linenr_T   prev_lnum = curwin->w_cursor.lnum;
     oparg_T    oa = { 0 };
     cmdarg_T   ca = { 0 };
@@ -3215,34 +3215,24 @@ pagescroll(int dir, long count, int half)
                count = n - curwin->w_height;
        }
 
-       // Scroll the window and determine number of lines to move the cursor.
+       // (Try to) scroll the window unless already at the end of the buffer.
        if (count > 0)
        {
-           validate_cursor();
-           int prev_wrow = curwin->w_wrow;
            nochange = scroll_with_sms(dir, count);
-           if (!nochange)
-           {
-               validate_cursor();
-               curscount = abs(prev_wrow - curwin->w_wrow);
-               dir = prev_wrow > curwin->w_wrow ? FORWARD : BACKWARD;
-           }
+           curwin->w_cursor.lnum = prev_lnum;
+           curwin->w_cursor.col = prev_col;
+           curwin->w_curswant = prev_curswant;
        }
 
-       int so = get_scrolloff_value();
-       // Move the cursor the same amount of screen lines except if
-       // 'scrolloff' is set and cursor was at start or end of buffer.
-       if (so == 0 || (prev_lnum != 1 && prev_lnum != buflen))
-       {
-           if (curwin->w_p_wrap)
-               nv_screengo(&oa, dir, curscount);
-           else if (dir == FORWARD)
-               cursor_down_inner(curwin, curscount);
-           else
-               cursor_up_inner(curwin, curscount);
-       }
+       // Move the cursor the same amount of screen lines.
+       if (curwin->w_p_wrap)
+           nv_screengo(&oa, dir, curscount);
+       else if (dir == FORWARD)
+           cursor_down_inner(curwin, curscount);
+       else
+           cursor_up_inner(curwin, curscount);
 
-       if (so > 0)
+       if (get_scrolloff_value() > 0)
            cursor_correct();
 #ifdef FEAT_FOLDING
        // Move cursor to first line of closed fold.
index 5b1bb402b69fcf1bc1a609f47b651d41f2f9efef..4f990954150527da3833117385365d9b20c30c8e 100644 (file)
@@ -4225,4 +4225,16 @@ func Test_single_line_filler_zb()
   bw!
 endfunc
 
+" Test for Ctrl-U not getting stuck at end of buffer with 'scrolloff'.
+func Test_halfpage_scrolloff_eob()
+  set scrolloff=5
+
+  call setline(1, range(1, 100))
+  exe "norm! Gzz\<C-U>zz"
+  call assert_notequal(100, line('.'))
+
+  set scrolloff&
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab nofoldenable
index e09c240a0981d4562109358fa9f88f2faeef2b8b..cda9bf0d78a53be24f1a0f33c87dae3a14d6518e 100644 (file)
@@ -1028,10 +1028,10 @@ func Test_smoothscroll_page()
   call assert_equal(415, col('.'))
   exe "norm! \<C-D>"
   call assert_equal(520, winsaveview().skipcol)
-  call assert_equal(535, col('.'))
+  call assert_equal(615, col('.'))
   exe "norm! \<C-D>"
   call assert_equal(520, winsaveview().skipcol)
-  call assert_equal(735, col('.'))
+  call assert_equal(815, col('.'))
   exe "norm! \<C-D>"
   call assert_equal(520, winsaveview().skipcol)
   call assert_equal(895, col('.'))
@@ -1043,10 +1043,10 @@ func Test_smoothscroll_page()
   call assert_equal(495, col('.'))
   exe "norm! \<C-U>"
   call assert_equal(0, winsaveview().skipcol)
-  call assert_equal(375, col('.'))
+  call assert_equal(295, col('.'))
   exe "norm! \<C-U>"
   call assert_equal(0, winsaveview().skipcol)
-  call assert_equal(175, col('.'))
+  call assert_equal(95, col('.'))
   exe "norm! \<C-U>"
   call assert_equal(0, winsaveview().skipcol)
   call assert_equal(15, col('.'))
index bafbe5b8ec0d873cd78e9d492c7d06e6d2753858..d3fde434cc7b4ef09feef9b2d0b1bb510cfff8aa 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    285,
 /**/
     284,
 /**/