@@ -1633,7 +1633,7 @@ scrolldown(
16331633
16341634 if (curwin -> w_cursor .lnum == curwin -> w_topline && do_sms )
16351635 {
1636- long so = curwin -> w_p_so >= 0 ? curwin -> w_p_so : p_so ;
1636+ long so = get_scrolloff_value () ;
16371637 int scrolloff_cols = so == 0 ? 0 : width1 + (so - 1 ) * width2 ;
16381638
16391639 // make sure the cursor is in the visible text
@@ -1684,8 +1684,7 @@ scrollup(
16841684 linenr_T prev_topline = curwin -> w_topline ;
16851685
16861686 if (do_sms )
1687- size = win_linetabsize (curwin , curwin -> w_topline ,
1688- ml_get (curwin -> w_topline ), (colnr_T )MAXCOL );
1687+ size = linetabsize (curwin , curwin -> w_topline );
16891688
16901689 // diff mode: first consume "topfill"
16911690 // 'smoothscroll': increase "w_skipcol" until it goes over the end of
@@ -1740,8 +1739,7 @@ scrollup(
17401739# endif
17411740 curwin -> w_skipcol = 0 ;
17421741 if (todo > 1 && do_sms )
1743- size = win_linetabsize (curwin , curwin -> w_topline ,
1744- ml_get (curwin -> w_topline ), (colnr_T )MAXCOL );
1742+ size = linetabsize (curwin , curwin -> w_topline );
17451743 }
17461744 }
17471745 }
@@ -1784,11 +1782,15 @@ scrollup(
17841782 {
17851783 int width1 = curwin -> w_width - curwin_col_off ();
17861784 int width2 = width1 + curwin_col_off2 ();
1787- long so = curwin -> w_p_so >= 0 ? curwin -> w_p_so : p_so ;
1785+ long so = get_scrolloff_value () ;
17881786 int scrolloff_cols = so == 0 ? 0 : width1 + (so - 1 ) * width2 ;
1787+ int space_cols = (curwin -> w_height - 1 ) * width2 ;
17891788
17901789 // Make sure the cursor is in a visible part of the line, taking
17911790 // 'scrolloff' into account, but using screen lines.
1791+ // If there are not enough screen lines put the cursor in the middle.
1792+ if (scrolloff_cols > space_cols / 2 )
1793+ scrolloff_cols = space_cols / 2 ;
17921794 validate_virtcol ();
17931795 if (curwin -> w_virtcol < curwin -> w_skipcol + 3 + scrolloff_cols )
17941796 {
@@ -1823,11 +1825,22 @@ adjust_skipcol(void)
18231825
18241826 int width1 = curwin -> w_width - curwin_col_off ();
18251827 int width2 = width1 + curwin_col_off2 ();
1826- long so = curwin -> w_p_so >= 0 ? curwin -> w_p_so : p_so ;
1828+ long so = get_scrolloff_value () ;
18271829 int scrolloff_cols = so == 0 ? 0 : width1 + (so - 1 ) * width2 ;
18281830 int scrolled = FALSE;
18291831
18301832 validate_virtcol ();
1833+ if (curwin -> w_cline_height == curwin -> w_height )
1834+ {
1835+ // the line just fits in the window, don't scroll
1836+ if (curwin -> w_skipcol != 0 )
1837+ {
1838+ curwin -> w_skipcol = 0 ;
1839+ redraw_later (UPD_NOT_VALID );
1840+ }
1841+ return ;
1842+ }
1843+
18311844 while (curwin -> w_skipcol > 0
18321845 && curwin -> w_virtcol < curwin -> w_skipcol + 3 + scrolloff_cols )
18331846 {
@@ -2691,6 +2704,19 @@ cursor_correct(void)
26912704 )
26922705 return ;
26932706
2707+ if (curwin -> w_p_sms && !curwin -> w_p_wrap )
2708+ {
2709+ // 'smoothscroll is active
2710+ if (curwin -> w_cline_height == curwin -> w_height )
2711+ {
2712+ // The cursor line just fits in the window, don't scroll.
2713+ curwin -> w_skipcol = 0 ;
2714+ return ;
2715+ }
2716+ // TODO: If the cursor line doesn't fit in the window then only adjust
2717+ // w_skipcol.
2718+ }
2719+
26942720 /*
26952721 * Narrow down the area where the cursor can be put by taking lines from
26962722 * the top and the bottom until:
0 commit comments