patch 9.1.0357: Page scrolling should place cursor at window boundaries

Commit: 
https://github.com/vim/vim/commit/4b6b0c4024df08dd8ce49dff3c76356ff81190c4
Author: Luuk van Baal <luukvb...@gmail.com>
Date:   Sat Apr 20 17:38:20 2024 +0200

    patch 9.1.0357: Page scrolling should place cursor at window boundaries
    
    Problem:  Page scrolling does not always place the cursor at the top or
              bottom of the window (Mathias Rav)
    Solution: Place the cursor at the top or bottom of the window.
              (Luuk van Baal)
    
    fixes: #14585
    closes: #14586
    
    Signed-off-by: Luuk van Baal <luukvb...@gmail.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/move.c b/src/move.c
index a234fca1d..1b6e003cc 100644
--- a/src/move.c
+++ b/src/move.c
@@ -3244,17 +3244,6 @@ pagescroll(int dir, long count, int half)
            cursor_down_inner(curwin, curscount);
        else
            cursor_up_inner(curwin, curscount);
-
-       if (get_scrolloff_value() > 0)
-           cursor_correct();
-#ifdef FEAT_FOLDING
-       // Move cursor to first line of closed fold.
-       foldAdjustCursor();
-#endif
-
-       nochange = nochange
-           && prev_col == curwin->w_cursor.col
-           && prev_lnum == curwin->w_cursor.lnum;
     }
     else
     {
@@ -3262,8 +3251,23 @@ pagescroll(int dir, long count, int half)
        count *= ((ONE_WINDOW && p_window > 0 && p_window < Rows - 1) ?
                                MAX(1, p_window - 2) : get_scroll_overlap(dir));
        nochange = scroll_with_sms(dir, count);
+
+       // Place cursor at top or bottom of window.
+       validate_botline();
+       curwin->w_cursor.lnum = (dir == FORWARD ? curwin->w_topline
+                                                   : curwin->w_botline - 1);
     }
 
+    if (get_scrolloff_value() > 0)
+       cursor_correct();
+#ifdef FEAT_FOLDING
+    // Move cursor to first line of closed fold.
+    foldAdjustCursor();
+#endif
+    nochange = nochange
+       && prev_col == curwin->w_cursor.col
+       && prev_lnum == curwin->w_cursor.lnum;
+
     // Error if both the viewport and cursor did not change.
     if (nochange)
        beep_flush();
diff --git a/src/testdir/test_normal.vim b/src/testdir/test_normal.vim
index 7fb6a4bf5..4b7e5e614 100644
--- a/src/testdir/test_normal.vim
+++ b/src/testdir/test_normal.vim
@@ -3813,8 +3813,8 @@ func Test_normal_vert_scroll_longline()
   call assert_equal(11, line('.'))
   call assert_equal(1, winline())
   exe "normal \<C-B>"
-  call assert_equal(10, line('.'))
-  call assert_equal(4, winline())
+  call assert_equal(11, line('.'))
+  call assert_equal(5, winline())
   exe "normal \<C-B>\<C-B>"
   call assert_equal(5, line('.'))
   call assert_equal(5, winline())
@@ -4247,4 +4247,17 @@ func Test_halfpage_cursor_startend()
   bwipe!
 endfunc
 
+" Test for Ctrl-F/B moving the cursor to the window boundaries.
+func Test_page_cursor_topbot()
+  10new
+  call setline(1, range(1, 100))
+  exe "norm! gg2\<C-F>"
+  call assert_equal(17, line('.'))
+  exe "norm! \<C-B>"
+  call assert_equal(18, line('.'))
+  exe "norm! \<C-B>\<C-F>"
+  call assert_equal(9, line('.'))
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab nofoldenable
diff --git a/src/version.c b/src/version.c
index 593ac4914..93798aa02 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 */
+/**/
+    357,
 /**/
     356,
 /**/

-- 
-- 
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/E1ryCti-004UPi-US%40256bit.org.

Raspunde prin e-mail lui