From 0697c24601e5d236bc17ca2d0c6b4cb9aaf2dd46 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Apr 2026 13:42:02 +0800 Subject: [PATCH] vim-patch:9.2.0413: Scrolling wrong with 'splitkeep' when changing 'cmdheight' (#39493) Problem: Cursor is not adjusted when 'cmdheight' is changed to cover the cursor with 'splitkeep' ~= "cursor". Solution: Handle window resize for 'splitkeep' after changing 'cmdheight'. Ensure previous window height is set when changing 'splitkeep' (Luuk van Baal). closes: vim/vim#20043 https://github.com/vim/vim/commit/bd0f3e6da5df70ab2250264d0a7efc7db83c3dc8 Co-authored-by: Luuk van Baal --- src/nvim/options.lua | 1 + src/nvim/optionstr.c | 8 ++++++++ src/nvim/window.c | 1 + test/old/testdir/test_window_cmd.vim | 10 ++++++++++ 4 files changed, 20 insertions(+) diff --git a/src/nvim/options.lua b/src/nvim/options.lua index 29115b5716..2651584a36 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -8633,6 +8633,7 @@ local options = { }, { abbreviation = 'spk', + cb = 'did_set_splitkeep', defaults = 'cursor', values = { 'cursor', 'screen', 'topline' }, desc = [=[ diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index 274fbb653c..74301ecab2 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -1831,6 +1831,14 @@ const char *did_set_spellsuggest(optset_T *args FUNC_ATTR_UNUSED) return NULL; } +const char *did_set_splitkeep(optset_T *args FUNC_ATTR_UNUSED) +{ + FOR_ALL_TAB_WINDOWS(tp, wp) { + wp->w_prev_height = wp->w_height; + } + return did_set_str_generic(args); +} + /// The 'statuscolumn' option is changed. const char *did_set_statuscolumn(optset_T *args) { diff --git a/src/nvim/window.c b/src/nvim/window.c index 40f471a9fb..7877dde592 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -7139,6 +7139,7 @@ void command_height(void) if (p_ch < old_p_ch && command_frame_height && frp != NULL) { frame_add_height(frp, (int)(old_p_ch - p_ch)); } + win_fix_scroll(true); // Recompute window positions. win_comp_pos(); diff --git a/test/old/testdir/test_window_cmd.vim b/test/old/testdir/test_window_cmd.vim index 8d77d3851f..4f4aec4ffb 100644 --- a/test/old/testdir/test_window_cmd.vim +++ b/test/old/testdir/test_window_cmd.vim @@ -1944,6 +1944,16 @@ func Test_splitkeep_screen_cursor_pos() set splitkeep& endfunc +func Test_splitkeep_cmdheight() + set splitkeep=screen + call setline(1, range(&lines)) + norm! G + set cmdheight=2 + call assert_equal(&lines - 1, line('.')) + %bwipeout! + set splitkeep& cmdheight& +endfunc + func Test_splitkeep_cursor() CheckScreendump let lines =<< trim END