Skip to content

Commit c97e869

Browse files
luukvbaalchrisbra
authored andcommitted
patch 9.1.0993: New 'cmdheight' behavior may be surprising
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: #16385 Signed-off-by: Luuk van Baal <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 3159b64 commit c97e869

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
> +0&#ffffff0@74
2-
|~+0#4040ff13&| @73
3-
|[+3#0000000&|N|o| |N|a|m|e|]| @47|0|,|0|-|1| @9|A|l@1
2+
|[+3&&|N|o| |N|a|m|e|]| @47|0|,|0|-|1| @9|A|l@1
43
| +0&&@74
54
@75
65
@75
76
@75
87
@75
8+
@75
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
> +0&#ffffff0@74
2+
|~+0#4040ff13&| @73
3+
|~| @73
4+
|~| @73
5+
|~| @73
6+
|[+3#0000000&|N|o| |N|a|m|e|]| @47|0|,|0|-|1| @9|A|l@1
7+
|:+0&&|w|i|n|c|m|d| |_| @65
8+
@75

src/testdir/test_cmdline.vim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,13 @@ func Test_changing_cmdheight()
293293
" :resize now also changes 'cmdheight' accordingly
294294
call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
295295
call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
296-
call term_sendkeys(buf, ":set cmdheight-=1\<CR>")
297296

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

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

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

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

318+
" window commands do not reduce 'cmdheight' to value lower than :set by user
319+
call term_sendkeys(buf, "\<CR>:wincmd _\<CR>")
320+
call VerifyScreenDump(buf, 'Test_changing_cmdheight_8', {})
321+
319322
" clean up
320323
call StopVimInTerminal(buf)
321324
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
993,
707709
/**/
708710
992,
709711
/**/

src/window.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3832,6 +3832,10 @@ frame_has_win(frame_T *frp, win_T *wp)
38323832
return FALSE;
38333833
}
38343834

3835+
// 'cmdheight' value explicitly set by the user: window commands are allowed to
3836+
// resize the topframe to values higher than this minimum, but not lower.
3837+
static int min_set_ch = 1;
3838+
38353839
/*
38363840
* Set a new height for a frame. Recursively sets the height for contained
38373841
* frames and windows. Caller must take care of positions.
@@ -3852,9 +3856,11 @@ frame_new_height(
38523856
if (topfrp->fr_parent == NULL && set_ch)
38533857
{
38543858
// topframe: update the command line height, with side effects.
3855-
int new_ch = MAX(1, p_ch + topfrp->fr_height - height);
3859+
int new_ch = MAX(min_set_ch, p_ch + topfrp->fr_height - height);
3860+
int save_ch = min_set_ch;
38563861
if (new_ch != p_ch)
38573862
set_option_value((char_u *)"cmdheight", new_ch, NULL, 0);
3863+
min_set_ch = save_ch;
38583864
height = MIN(height, ROWS_AVAIL);
38593865
}
38603866
if (topfrp->fr_win != NULL)
@@ -7306,7 +7312,7 @@ command_height(void)
73067312
old_p_ch += h;
73077313
frp = frp->fr_prev;
73087314
}
7309-
if (p_ch < old_p_ch && command_frame_height)
7315+
if (p_ch < old_p_ch && command_frame_height && frp != NULL)
73107316
frame_add_height(frp, (int)(old_p_ch - p_ch));
73117317

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

73307337
/*

0 commit comments

Comments
 (0)