Patch 9.0.0908
Problem:    With 'smoothscroll' cursor may end up in wrong position.
Solution:   Correct the computation of screen lines. (Yee Cheng Chin,
            closes #11502)
Files:      src/move.c, src/testdir/test_scroll_opt.vim,
            src/testdir/dumps/Test_smooth_long_1.dump,
            src/testdir/dumps/Test_smooth_long_10.dump,
            src/testdir/dumps/Test_smooth_long_11.dump,
            src/testdir/dumps/Test_smooth_long_12.dump,
            src/testdir/dumps/Test_smooth_long_2.dump,
            src/testdir/dumps/Test_smooth_long_3.dump,
            src/testdir/dumps/Test_smooth_long_4.dump,
            src/testdir/dumps/Test_smooth_long_5.dump,
            src/testdir/dumps/Test_smooth_long_6.dump,
            src/testdir/dumps/Test_smooth_long_7.dump,
            src/testdir/dumps/Test_smooth_long_8.dump,
            src/testdir/dumps/Test_smooth_long_9.dump


*** ../vim-9.0.0907/src/move.c  2022-11-18 22:14:04.802988148 +0000
--- src/move.c  2022-11-19 12:21:06.625991130 +0000
***************
*** 2460,2477 ****
      used = curwin->w_cline_height;
  #endif
  
!     // If the cursor is below botline, we will at least scroll by the height
!     // of the cursor line.  Correct for empty lines, which are really part of
!     // botline.
      if (cln >= curwin->w_botline)
      {
        scrolled = used;
        if (cln == curwin->w_botline)
            scrolled -= curwin->w_empty_rows;
        min_scrolled = scrolled;
!       if (cln > curwin->w_botline && curwin->w_p_sms && curwin->w_p_wrap)
!           for (linenr_T lnum = curwin->w_botline + 1; lnum <= cln; ++lnum)
!               min_scrolled += PLINES_NOFILL(lnum);
      }
  
      /*
--- 2460,2509 ----
      used = curwin->w_cline_height;
  #endif
  
!     // If the cursor is on or below botline, we will at least scroll by the
!     // height of the cursor line, which is "used".  Correct for empty lines,
!     // which are really part of botline.
      if (cln >= curwin->w_botline)
      {
        scrolled = used;
        if (cln == curwin->w_botline)
            scrolled -= curwin->w_empty_rows;
        min_scrolled = scrolled;
!       if (curwin->w_p_sms && curwin->w_p_wrap)
!       {
!           // 'smoothscroll' and 'wrap' are set
!           if (cln > curwin->w_botline)
!               // add screen lines below w_botline
!               for (linenr_T lnum = curwin->w_botline + 1; lnum <= cln; ++lnum)
!                   min_scrolled += PLINES_NOFILL(lnum);
! 
!           // Calculate how many screen lines the current top line of window
!           // occupies. If it is occupying more than the entire window, we
!           // need to scroll the additional clipped lines to scroll past the
!           // top line before we can move on to the other lines.
!           int top_plines =
! #ifdef FEAT_DIFF
!                           plines_win_nofill
! #else
!                           plines_win
! #endif
!                                       (curwin, curwin->w_topline, FALSE);
!           int skip_lines = 0;
!           int width1 = curwin->w_width - curwin_col_off();
!           int width2 = width1 + curwin_col_off2();
!           // similar formula is used in curs_columns()
!           if (curwin->w_skipcol > width1)
!               skip_lines += (curwin->w_skipcol - width1) / width2 + 1;
!           else if (curwin->w_skipcol > 0)
!               skip_lines = 1;
! 
!           top_plines -= skip_lines;
!           if (top_plines > curwin->w_height)
!           {
!               scrolled += (top_plines - curwin->w_height);
!               min_scrolled += (top_plines - curwin->w_height);
!           }
!       }
      }
  
      /*
*** ../vim-9.0.0907/src/testdir/test_scroll_opt.vim     2022-11-18 
12:52:23.418570894 +0000
--- src/testdir/test_scroll_opt.vim     2022-11-19 12:22:47.158078328 +0000
***************
*** 246,252 ****
  
    let lines =<< trim END
        vim9script
!       setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30))])
        set smoothscroll scrolloff=0
        normal 3G10|zt
    END
--- 246,252 ----
  
    let lines =<< trim END
        vim9script
!       setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30)) 
.. ' end', 'four'])
        set smoothscroll scrolloff=0
        normal 3G10|zt
    END
***************
*** 287,292 ****
--- 287,316 ----
    call term_sendkeys(buf, "gj")
    call term_sendkeys(buf, "\<C-Y>")
    call VerifyScreenDump(buf, 'Test_smooth_long_9', {})
+ 
+   " 'scrolloff' set to 0, move cursor down one line.
+   " Cursor should move properly, and since this is a really long line, it will
+   " be put on top of the screen.
+   call term_sendkeys(buf, ":set scrolloff=0\<CR>")
+   call term_sendkeys(buf, "0j")
+   call VerifyScreenDump(buf, 'Test_smooth_long_10', {})
+ 
+   " Repeat the step and move the cursor down again.
+   " This time, use a shorter long line that is barely long enough to span more
+   " than one window. Note that the cursor is at the bottom this time because
+   " Vim prefers to do so if we are scrolling a few lines only.
+   call term_sendkeys(buf, ":call setline(1, ['one', 'two', 'Line' .. (' with 
lots of text'->repeat(10)) .. ' end', 'four'])\<CR>")
+   call term_sendkeys(buf, "3Gzt")
+   call term_sendkeys(buf, "j")
+   call VerifyScreenDump(buf, 'Test_smooth_long_11', {})
+ 
+   " Repeat the step but this time start it when the line is smooth-scrolled by
+   " one line. This tests that the offset calculation is still correct and
+   " still end up scrolling down to the next line with cursor at bottom of
+   " screen.
+   call term_sendkeys(buf, "3Gzt")
+   call term_sendkeys(buf, "\<C-E>j")
+   call VerifyScreenDump(buf, 'Test_smooth_long_12', {})
    
    call StopVimInTerminal(buf)
  endfunc
*** ../vim-9.0.0907/src/testdir/dumps/Test_smooth_long_1.dump   2022-10-08 
21:13:16.632848892 +0100
--- src/testdir/dumps/Test_smooth_long_1.dump   2022-11-19 12:13:10.677547740 
+0000
***************
*** 3,6 ****
  |h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| 
|l|o
  |t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
  |f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
! | @21|3|,|1|0| @9|B|o|t| 
--- 3,6 ----
  |h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| 
|l|o
  |t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
  |f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
! | @21|3|,|1|0| @9|6@1|%| 
*** ../vim-9.0.0907/src/testdir/dumps/Test_smooth_long_10.dump  2022-11-19 
12:24:25.118161924 +0000
--- src/testdir/dumps/Test_smooth_long_10.dump  2022-11-19 12:13:10.677547740 
+0000
***************
*** 0 ****
--- 1,6 ----
+ >f+0&#ffffff0|o|u|r| @35
+ |~+0#4040ff13&| @38
+ |~| @38
+ |~| @38
+ |~| @38
+ |:+0#0000000&|s|e|t| |s|c|r|o|l@1|o| @9|4|,|1| @10|B|o|t| 
*** ../vim-9.0.0907/src/testdir/dumps/Test_smooth_long_11.dump  2022-11-19 
12:24:25.122161928 +0000
--- src/testdir/dumps/Test_smooth_long_11.dump  2022-11-19 12:13:10.677547740 
+0000
***************
*** 0 ****
--- 1,6 ----
+ |<+0#4040ff13#ffffff0@2|t+0#0000000&|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| 
|l|o|t|s| |o|f| |t|e|x|t| |w|i|t
+ |h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| 
|l|o
+ |t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
+ |f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |e|n|d| @11
+ >f|o|u|r| @35
+ @22|4|,|1| @10|B|o|t| 
*** ../vim-9.0.0907/src/testdir/dumps/Test_smooth_long_12.dump  2022-11-19 
12:24:25.126161929 +0000
--- src/testdir/dumps/Test_smooth_long_12.dump  2022-11-19 12:13:10.677547740 
+0000
***************
*** 0 ****
--- 1,6 ----
+ |<+0#4040ff13#ffffff0@2|t+0#0000000&|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| 
|l|o|t|s| |o|f| |t|e|x|t| |w|i|t
+ |h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| 
|l|o
+ |t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
+ |f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |e|n|d| @11
+ |f|o|u>r| @35
+ @22|4|,|4| @10|B|o|t| 
*** ../vim-9.0.0907/src/testdir/dumps/Test_smooth_long_2.dump   2022-10-08 
21:13:16.632848892 +0100
--- src/testdir/dumps/Test_smooth_long_2.dump   2022-11-19 12:13:10.677547740 
+0000
***************
*** 3,6 ****
  |t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
  |f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
  |x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w
! | @21|3|,|5|0| @9|B|o|t| 
--- 3,6 ----
  |t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
  |f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
  |x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w
! | @21|3|,|5|0| @9|6@1|%| 
*** ../vim-9.0.0907/src/testdir/dumps/Test_smooth_long_3.dump   2022-10-08 
21:13:16.632848892 +0100
--- src/testdir/dumps/Test_smooth_long_3.dump   2022-11-19 12:13:10.677547740 
+0000
***************
*** 3,6 ****
  | |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o|f| 
  |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e|x|t
  | |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w|i|t
! | @21|3|,|2|5|0| @8|B|o|t| 
--- 3,6 ----
  | |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o|f| 
  |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e|x|t
  | |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w|i|t
! | @21|3|,|2|5|0| @8|6@1|%| 
*** ../vim-9.0.0907/src/testdir/dumps/Test_smooth_long_4.dump   2022-10-08 
21:13:16.632848892 +0100
--- src/testdir/dumps/Test_smooth_long_4.dump   2022-11-19 12:13:10.677547740 
+0000
***************
*** 3,6 ****
  |t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
  |f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
  |x|t| |w|i|t|h| |l>o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w
! | @21|3|,|2|1|0| @8|B|o|t| 
--- 3,6 ----
  |t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
  |f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
  |x|t| |w|i|t|h| |l>o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w
! | @21|3|,|2|1|0| @8|6@1|%| 
*** ../vim-9.0.0907/src/testdir/dumps/Test_smooth_long_5.dump   2022-10-08 
21:13:16.632848892 +0100
--- src/testdir/dumps/Test_smooth_long_5.dump   2022-11-19 12:13:10.677547740 
+0000
***************
*** 3,6 ****
  |h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| 
|l|o
  |t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
  |f| |t|e|x|t| |w|i>t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
! | @21|3|,|1|7|0| @8|B|o|t| 
--- 3,6 ----
  |h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| 
|l|o
  |t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
  |f| |t|e|x|t| |w|i>t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
! | @21|3|,|1|7|0| @8|6@1|%| 
*** ../vim-9.0.0907/src/testdir/dumps/Test_smooth_long_6.dump   2022-10-09 
17:19:04.445451418 +0100
--- src/testdir/dumps/Test_smooth_long_6.dump   2022-11-19 12:13:10.677547740 
+0000
***************
*** 3,6 ****
  |t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
  |f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
  |x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w
! | @21|3|,|9|0| @9|B|o|t| 
--- 3,6 ----
  |t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
  |f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
  |x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w
! | @21|3|,|9|0| @9|6@1|%| 
*** ../vim-9.0.0907/src/testdir/dumps/Test_smooth_long_7.dump   2022-10-09 
17:19:04.445451418 +0100
--- src/testdir/dumps/Test_smooth_long_7.dump   2022-11-19 12:13:10.677547740 
+0000
***************
*** 3,6 ****
  |t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
  |f| |t|e|x|t| |w|i>t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
  |x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w
! | @21|3|,|1|7|0| @8|B|o|t| 
--- 3,6 ----
  |t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
  |f| |t|e|x|t| |w|i>t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
  |x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w
! | @21|3|,|1|7|0| @8|6@1|%| 
*** ../vim-9.0.0907/src/testdir/dumps/Test_smooth_long_8.dump   2022-10-12 
19:53:10.621726849 +0100
--- src/testdir/dumps/Test_smooth_long_8.dump   2022-11-19 12:13:10.677547740 
+0000
***************
*** 3,6 ****
  |t|s| |o|f| |t|e|x>t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
  |f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
  |x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w
! |:|s|e|t| |s|c|r|o|l@1|o| @9|3|,|1|3|0| @8|B|o|t| 
--- 3,6 ----
  |t|s| |o|f| |t|e|x>t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
  |f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
  |x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w
! |:|s|e|t| |s|c|r|o|l@1|o| @9|3|,|1|3|0| @8|6@1|%| 
*** ../vim-9.0.0907/src/testdir/dumps/Test_smooth_long_9.dump   2022-10-20 
20:15:40.987639315 +0100
--- src/testdir/dumps/Test_smooth_long_9.dump   2022-11-19 12:13:10.677547740 
+0000
***************
*** 3,6 ****
  |f| |t|e|x|t| |w|i>t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
  |x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w
  |i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w|i|t|h| 
! @22|3|,|1|7|0| @8|B|o|t| 
--- 3,6 ----
  |f| |t|e|x|t| |w|i>t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
  |x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w
  |i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w|i|t|h| 
! @22|3|,|1|7|0| @8|6@1|%| 
*** ../vim-9.0.0907/src/version.c       2022-11-19 11:41:26.345764390 +0000
--- src/version.c       2022-11-19 12:15:18.281673195 +0000
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     908,
  /**/

-- 
I AM THANKFUL...
...for the clothes that fit a little too snug because it
means I have more than enough to eat.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20221119122550.40E221C132E%40moolenaar.net.

Raspunde prin e-mail lui