]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0881: 'smoothscroll' position is lost when the window height changes v9.2.0881
authorHirohito Higashi <h.east.727@gmail.com>
Thu, 30 Jul 2026 19:40:11 +0000 (19:40 +0000)
committerChristian Brabandt <cb@256bit.org>
Thu, 30 Jul 2026 19:40:11 +0000 (19:40 +0000)
Problem:  With 'smoothscroll' the scroll position of a window is lost when
          its height changes.
Solution: Only reset the skipped columns when 'smoothscroll' is off, where
          they just serve to keep the cursor visible.

closes: #20885

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_scroll_opt.vim
src/version.c
src/window.c

index 6d4fc81b8193f1cc2ee7ece4f53b3efaa77ca0a0..cf362b6a29a67ee8646c7901a1d1dc96f64462b6 100644 (file)
@@ -1306,6 +1306,30 @@ func Test_smoothscroll_next_topline()
   bwipe!
 endfunc
 
+func Test_smoothscroll_keep_skipcol()
+  call NewWindow(10, 40)
+  setlocal smoothscroll
+  call setline(1, ['abcde '->repeat(150)]->repeat(2))
+
+  exe "norm! 10\<C-E>"
+  redraw
+  let skipcol = winsaveview().skipcol
+  call assert_notequal(0, skipcol)
+
+  " Changing the height of the window must not reset the scroll position.
+  resize -3
+  resize +3
+  redraw
+  call assert_equal(skipcol, winsaveview().skipcol)
+
+  " Using the autocommand window changes the height as well.
+  call bufload(bufadd(''))
+  redraw
+  call assert_equal(skipcol, winsaveview().skipcol)
+
+  bwipe!
+endfunc
+
 func Test_smoothscroll_long_line_zb()
   call NewWindow(10, 40)
   call setline(1, 'abcde '->repeat(150))
index caef0f750aeef2a1b47e4a076d9cd76003bce87c..7f650d214ab89df63989a449f00234923ed5046b 100644 (file)
@@ -758,6 +758,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    881,
 /**/
     880,
 /**/
index f2ee69071d5599c3218b559fb04d16f291a68e2e..04d3d86c4ef98a0d0b62cac7b3157a8bcfafd6aa 100644 (file)
@@ -7413,7 +7413,10 @@ win_new_height(win_T *wp, int height)
     // values might be invalid.
     if (!exiting && *p_spk == 'c')
     {
-       wp->w_skipcol = 0;
+       // With 'smoothscroll' w_skipcol is the scroll position, keep it.
+       // Otherwise it only keeps the cursor visible and is computed again.
+       if (!wp->w_p_sms)
+           wp->w_skipcol = 0;
        scroll_to_fraction(wp, prev_height);
     }
 }
@@ -7469,14 +7472,16 @@ scroll_to_fraction(win_T *wp, int prev_height)
            if (wp->w_wrow >= wp->w_height
                                       && (wp->w_width - win_col_off(wp)) > 0)
            {
-               wp->w_skipcol += wp->w_width - win_col_off(wp);
+               // The cursor must be visible, override the scroll position.
+               colnr_T skipcol = wp->w_width - win_col_off(wp);
+
                --wp->w_wrow;
                while (wp->w_wrow >= wp->w_height)
                {
-                   wp->w_skipcol += wp->w_width - win_col_off(wp)
-                                                          + win_col_off2(wp);
+                   skipcol += wp->w_width - win_col_off(wp) + win_col_off2(wp);
                    --wp->w_wrow;
                }
+               wp->w_skipcol = skipcol;
            }
        }
        else if (sline > 0)