patch 9.0.1772: Cursor may be adjusted in 'splitkeep'ed windows
Problem: Cursor is adjusted in window that did not change in size by
'splitkeep'.
Solution: Only check that cursor position is valid in a window that
has changed in size.
closes: #12509
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Luuk van Baal <luukvbaal@gmail.com>
diff --git a/src/window.c b/src/window.c
index 833ee56..152365e 100644
--- a/src/window.c
+++ b/src/window.c
@@ -6789,6 +6789,10 @@
// Skip when window height has not changed.
if (wp->w_height != wp->w_prev_height)
{
+ // Cursor position in this window may now be invalid. It is kept
+ // potentially invalid until the window is made the current window.
+ wp->w_do_win_fix_cursor = TRUE;
+
// If window has moved update botline to keep the same screenlines.
if (*p_spk == 's' && wp->w_winrow != wp->w_prev_winrow
&& wp->w_botline - 1 <= wp->w_buffer->b_ml.ml_line_count)
@@ -6813,6 +6817,7 @@
}
else if (wp == curwin)
wp->w_valid &= ~VALID_CROW;
+
invalidate_botline_win(wp);
validate_botline_win(wp);
}
@@ -6830,7 +6835,7 @@
/*
* Make sure the cursor position is valid for 'splitkeep'.
* If it is not, put the cursor position in the jumplist and move it.
- * If we are not in normal mode ("normal" is zero), make it valid by scrolling
+ * If we are not in normal mode ("normal" is FALSE), make it valid by scrolling
* instead.
*/
static void
@@ -6838,9 +6843,12 @@
{
win_T *wp = curwin;
- if (skip_win_fix_cursor || wp->w_buffer->b_ml.ml_line_count < wp->w_height)
+ if (skip_win_fix_cursor
+ || !wp->w_do_win_fix_cursor
+ || wp->w_buffer->b_ml.ml_line_count < wp->w_height)
return;
+ wp->w_do_win_fix_cursor = FALSE;
// Determine valid cursor range.
long so = MIN(wp->w_height / 2, get_scrolloff_value());
linenr_T lnum = wp->w_cursor.lnum;
@@ -6873,7 +6881,7 @@
{
wp->w_fraction = (nlnum == bot) ? FRACTION_MULT : 0;
scroll_to_fraction(wp, wp->w_prev_height);
- validate_botline_win(curwin);
+ validate_botline();
}
}
}