@@ -1406,7 +1406,7 @@ win_split_ins(
14061406 win_equal (wp , TRUE,
14071407 (flags & WSP_VERT ) ? (dir == 'v' ? 'b' : 'h' )
14081408 : dir == 'h' ? 'b' : 'v' );
1409- else if (* p_spk != 'c' && !is_aucmd_win (wp ))
1409+ else if (!is_aucmd_win (wp ))
14101410 win_fix_scroll (FALSE);
14111411
14121412 // Don't change the window height/width to 'winheight' / 'winwidth' if a
@@ -2012,7 +2012,7 @@ win_equal(
20122012 win_equal_rec (next_curwin == NULL ? curwin : next_curwin , current ,
20132013 topframe , dir , 0 , tabline_height (),
20142014 (int )Columns , topframe -> fr_height );
2015- if (* p_spk != 'c' && !is_aucmd_win (next_curwin ))
2015+ if (!is_aucmd_win (next_curwin ))
20162016 win_fix_scroll (TRUE);
20172017}
20182018
@@ -2822,8 +2822,7 @@ win_close(win_T *win, int free_buf)
28222822 else
28232823 {
28242824 win_comp_pos ();
2825- if (* p_spk != 'c' )
2826- win_fix_scroll (FALSE);
2825+ win_fix_scroll (FALSE);
28272826 }
28282827 if (close_curwin )
28292828 {
@@ -5906,7 +5905,7 @@ shell_new_rows(void)
59065905 compute_cmdrow ();
59075906 curtab -> tp_ch_used = p_ch ;
59085907
5909- if (* p_spk != 'c' && !skip_win_fix_scroll )
5908+ if (!skip_win_fix_scroll )
59105909 win_fix_scroll (TRUE);
59115910
59125911#if 0
@@ -6111,8 +6110,7 @@ win_setheight_win(int height, win_T *win)
61116110 msg_row = row ;
61126111 msg_col = 0 ;
61136112
6114- if (* p_spk != 'c' )
6115- win_fix_scroll (TRUE);
6113+ win_fix_scroll (TRUE);
61166114
61176115 redraw_all_later (UPD_NOT_VALID );
61186116}
@@ -6642,8 +6640,7 @@ win_drag_status_line(win_T *dragwin, int offset)
66426640 p_ch = MAX (Rows - cmdline_row , 1 );
66436641 curtab -> tp_ch_used = p_ch ;
66446642
6645- if (* p_spk != 'c' )
6646- win_fix_scroll (TRUE);
6643+ win_fix_scroll (TRUE);
66476644
66486645 redraw_all_later (UPD_SOME_VALID );
66496646 showmode ();
@@ -6772,21 +6769,22 @@ set_fraction(win_T *wp)
67726769}
67736770
67746771/*
6775- * Handle scroll position for 'splitkeep'. Replaces scroll_to_fraction()
6776- * call from win_new_height(). Instead we iterate over all windows in a
6777- * tabpage and calculate the new scroll position.
6772+ * Handle scroll position, depending on 'splitkeep'. Replaces the
6773+ * scroll_to_fraction() call from win_new_height() if 'splitkeep' is "screen"
6774+ * or "topline". Instead we iterate over all windows in a tabpage and
6775+ * calculate the new scroll position.
67786776 * TODO: Ensure this also works with wrapped lines.
6779- * Requires topline to be able to be set to a bufferline with some
6780- * offset(row-wise scrolling/ smoothscroll) .
6777+ * Requires a not fully visible cursor line to be allowed at the bottom of
6778+ * a window("zb"), probably only when ' smoothscroll' is also set .
67816779 */
67826780 static void
67836781win_fix_scroll (int resize )
67846782{
6785- int diff ;
6786- win_T * wp ;
6787- linenr_T lnum ;
6783+ if (* p_spk == 'c' )
6784+ return ; // 'splitkeep' is "cursor"
67886785
67896786 skip_update_topline = TRUE;
6787+ win_T * wp ;
67906788 FOR_ALL_WINDOWS (wp )
67916789 {
67926790 // Skip when window height has not changed.
@@ -6796,18 +6794,22 @@ win_fix_scroll(int resize)
67966794 if (* p_spk == 's' && wp -> w_winrow != wp -> w_prev_winrow
67976795 && wp -> w_botline - 1 <= wp -> w_buffer -> b_ml .ml_line_count )
67986796 {
6799- lnum = wp -> w_cursor . lnum ;
6800- diff = (wp -> w_winrow - wp -> w_prev_winrow )
6801- + ( wp -> w_height - wp -> w_prev_height ) ;
6797+ int diff = ( wp -> w_winrow - wp -> w_prev_winrow )
6798+ + (wp -> w_height - wp -> w_prev_height );
6799+ linenr_T lnum = wp -> w_cursor . lnum ;
68026800 wp -> w_cursor .lnum = wp -> w_botline - 1 ;
6801+
68036802 // Add difference in height and row to botline.
68046803 if (diff > 0 )
68056804 cursor_down_inner (wp , diff );
68066805 else
68076806 cursor_up_inner (wp , - diff );
6808- // Bring the new cursor position to the bottom of the screen.
6807+
6808+ // Scroll to put the new cursor position at the bottom of the
6809+ // screen.
68096810 wp -> w_fraction = FRACTION_MULT ;
68106811 scroll_to_fraction (wp , wp -> w_prev_height );
6812+
68116813 wp -> w_cursor .lnum = lnum ;
68126814 }
68136815 else if (wp == curwin )
@@ -6835,32 +6837,33 @@ win_fix_scroll(int resize)
68356837 static void
68366838win_fix_cursor (int normal )
68376839{
6838- long so = get_scrolloff_value ();
68396840 win_T * wp = curwin ;
6840- linenr_T nlnum = 0 ;
6841- linenr_T lnum = wp -> w_cursor .lnum ;
6842- linenr_T bot ;
6843- linenr_T top ;
68446841
6845- if (wp -> w_buffer -> b_ml .ml_line_count < wp -> w_height )
6846- return ;
6847- if (skip_win_fix_cursor )
6842+ if (skip_win_fix_cursor || wp -> w_buffer -> b_ml .ml_line_count < wp -> w_height )
68486843 return ;
68496844
68506845 // Determine valid cursor range.
6851- so = MIN (wp -> w_height / 2 , so );
6846+ long so = MIN (wp -> w_height / 2 , get_scrolloff_value ());
6847+ linenr_T lnum = wp -> w_cursor .lnum ;
6848+
68526849 wp -> w_cursor .lnum = wp -> w_topline ;
6853- top = cursor_down_inner (wp , so );
6850+ cursor_down_inner (wp , so );
6851+ linenr_T top = wp -> w_cursor .lnum ;
6852+
68546853 wp -> w_cursor .lnum = wp -> w_botline - 1 ;
6855- bot = cursor_up_inner (wp , so );
6854+ cursor_up_inner (wp , so );
6855+ linenr_T bot = wp -> w_cursor .lnum ;
6856+
68566857 wp -> w_cursor .lnum = lnum ;
6858+
68576859 // Check if cursor position is above or below valid cursor range.
6860+ linenr_T nlnum = 0 ;
68586861 if (lnum > bot && (wp -> w_botline - wp -> w_buffer -> b_ml .ml_line_count ) != 1 )
68596862 nlnum = bot ;
68606863 else if (lnum < top && wp -> w_topline != 1 )
68616864 nlnum = (so == wp -> w_height / 2 ) ? bot : top ;
68626865
6863- if (nlnum ) // Cursor is invalid for current scroll position.
6866+ if (nlnum != 0 ) // Cursor is invalid for current scroll position.
68646867 {
68656868 if (normal ) // Save to jumplist and set cursor to avoid scrolling.
68666869 {
0 commit comments