Skip to content

Commit

Permalink
patch 9.1.0993: New 'cmdheight' behavior may be surprising
Browse files Browse the repository at this point in the history
Problem:  Although patch 9.1.0990 fixed a real problem/inconsistency,
          it also introduced new behavior that may break BWC and/or be
          unexpected. Before 9.1.0990, window commands could make the
          topframe smaller (without changing 'cmdheight'; quirk that is
          now fixed), but did not allow extending the topframe beyond
          the 'cmdheight' set by the user. After 9.1.0990, the user can
          reduce the 'cmdheight' below the value they set explicitly,
          through window commands, which may lead to confusion.
          (aftere v9.1.0990)
Solution: Store the value explicitly set by the user and clamp the
          'cmdheight' when resizing the topframe. This also applies to
          dragging laststatus, which in contrast to window commands
          _did_ allow reducing the 'cmdheight' to values below the one
          set by the user. So with this patch there is still new
          behavior, but I think in a way that is less surprising.
          While at it, also fix a Coverity warning, introduced in
          v9.1.0990 (Luuk van Baal)

closes: vim#16385

Signed-off-by: Luuk van Baal <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
  • Loading branch information
luukvbaal authored and chrisbra committed Jan 6, 2025
1 parent 3159b64 commit c97e869
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/testdir/dumps/Test_changing_cmdheight_3.dump
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
> +0&#ffffff0@74
|~+0#4040ff13&| @73
|[+3#0000000&|N|o| |N|a|m|e|]| @47|0|,|0|-|1| @9|A|l@1
|[+3&&|N|o| |N|a|m|e|]| @47|0|,|0|-|1| @9|A|l@1
| +0&&@74
@75
@75
@75
@75
@75
8 changes: 8 additions & 0 deletions src/testdir/dumps/Test_changing_cmdheight_8.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
> +0&#ffffff0@74
|~+0#4040ff13&| @73
|~| @73
|~| @73
|~| @73
|[+3#0000000&|N|o| |N|a|m|e|]| @47|0|,|0|-|1| @9|A|l@1
|:+0&&|w|i|n|c|m|d| |_| @65
@75
9 changes: 6 additions & 3 deletions src/testdir/test_cmdline.vim
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,13 @@ func Test_changing_cmdheight()
" :resize now also changes 'cmdheight' accordingly
call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
call term_sendkeys(buf, ":set cmdheight-=1\<CR>")

" using more space moves the status line up
call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})

" reducing cmdheight moves status line down
call term_sendkeys(buf, ":set cmdheight-=2\<CR>")
call term_sendkeys(buf, ":set cmdheight-=3\<CR>")
call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})

" reducing window size and then setting cmdheight
Expand All @@ -312,10 +311,14 @@ func Test_changing_cmdheight()
call term_sendkeys(buf, ":call EchoTwo()\<CR>")
call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})

" decreasing 'cmdheight' doesn't clear the messages that need hit-enter
" increasing 'cmdheight' doesn't clear the messages that need hit-enter
call term_sendkeys(buf, ":call EchoOne()\<CR>")
call VerifyScreenDump(buf, 'Test_changing_cmdheight_7', {})

" window commands do not reduce 'cmdheight' to value lower than :set by user
call term_sendkeys(buf, "\<CR>:wincmd _\<CR>")
call VerifyScreenDump(buf, 'Test_changing_cmdheight_8', {})

" clean up
call StopVimInTerminal(buf)
endfunc
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
993,
/**/
992,
/**/
Expand Down
11 changes: 9 additions & 2 deletions src/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -3832,6 +3832,10 @@ frame_has_win(frame_T *frp, win_T *wp)
return FALSE;
}

// 'cmdheight' value explicitly set by the user: window commands are allowed to
// resize the topframe to values higher than this minimum, but not lower.
static int min_set_ch = 1;

/*
* Set a new height for a frame. Recursively sets the height for contained
* frames and windows. Caller must take care of positions.
Expand All @@ -3852,9 +3856,11 @@ frame_new_height(
if (topfrp->fr_parent == NULL && set_ch)
{
// topframe: update the command line height, with side effects.
int new_ch = MAX(1, p_ch + topfrp->fr_height - height);
int new_ch = MAX(min_set_ch, p_ch + topfrp->fr_height - height);
int save_ch = min_set_ch;
if (new_ch != p_ch)
set_option_value((char_u *)"cmdheight", new_ch, NULL, 0);
min_set_ch = save_ch;
height = MIN(height, ROWS_AVAIL);
}
if (topfrp->fr_win != NULL)
Expand Down Expand Up @@ -7306,7 +7312,7 @@ command_height(void)
old_p_ch += h;
frp = frp->fr_prev;
}
if (p_ch < old_p_ch && command_frame_height)
if (p_ch < old_p_ch && command_frame_height && frp != NULL)
frame_add_height(frp, (int)(old_p_ch - p_ch));

// Recompute window positions.
Expand All @@ -7325,6 +7331,7 @@ command_height(void)
// GUI starts up, we can't be sure in what order things happen. And when
// p_ch was changed in another tab page.
curtab->tp_ch_used = p_ch;
min_set_ch = p_ch;
}

/*
Expand Down

0 comments on commit c97e869

Please sign in to comment.