@@ -2460,18 +2460,50 @@ scroll_cursor_bot(int min_scroll, int set_topbot)
24602460 used = curwin -> w_cline_height ;
24612461#endif
24622462
2463- // If the cursor is below botline, we will at least scroll by the height
2464- // of the cursor line. Correct for empty lines, which are really part of
2465- // botline.
2463+ // If the cursor is on or below botline, we will at least scroll by the
2464+ // height of the cursor line, which is "used" . Correct for empty lines,
2465+ // which are really part of botline.
24662466 if (cln >= curwin -> w_botline )
24672467 {
24682468 scrolled = used ;
24692469 if (cln == curwin -> w_botline )
24702470 scrolled -= curwin -> w_empty_rows ;
24712471 min_scrolled = scrolled ;
2472- if (cln > curwin -> w_botline && curwin -> w_p_sms && curwin -> w_p_wrap )
2473- for (linenr_T lnum = curwin -> w_botline + 1 ; lnum <= cln ; ++ lnum )
2474- min_scrolled += PLINES_NOFILL (lnum );
2472+ if (curwin -> w_p_sms && curwin -> w_p_wrap )
2473+ {
2474+ // 'smoothscroll' and 'wrap' are set
2475+ if (cln > curwin -> w_botline )
2476+ // add screen lines below w_botline
2477+ for (linenr_T lnum = curwin -> w_botline + 1 ; lnum <= cln ; ++ lnum )
2478+ min_scrolled += PLINES_NOFILL (lnum );
2479+
2480+ // Calculate how many screen lines the current top line of window
2481+ // occupies. If it is occupying more than the entire window, we
2482+ // need to scroll the additional clipped lines to scroll past the
2483+ // top line before we can move on to the other lines.
2484+ int top_plines =
2485+ #ifdef FEAT_DIFF
2486+ plines_win_nofill
2487+ #else
2488+ plines_win
2489+ #endif
2490+ (curwin , curwin -> w_topline , FALSE);
2491+ int skip_lines = 0 ;
2492+ int width1 = curwin -> w_width - curwin_col_off ();
2493+ int width2 = width1 + curwin_col_off2 ();
2494+ // similar formula is used in curs_columns()
2495+ if (curwin -> w_skipcol > width1 )
2496+ skip_lines += (curwin -> w_skipcol - width1 ) / width2 + 1 ;
2497+ else if (curwin -> w_skipcol > 0 )
2498+ skip_lines = 1 ;
2499+
2500+ top_plines -= skip_lines ;
2501+ if (top_plines > curwin -> w_height )
2502+ {
2503+ scrolled += (top_plines - curwin -> w_height );
2504+ min_scrolled += (top_plines - curwin -> w_height );
2505+ }
2506+ }
24752507 }
24762508
24772509 /*
0 commit comments