Skip to content

Commit 1c329c0

Browse files
committed
patch 8.1.2227: layout wrong if 'lines' changes while cmdline window is open
Problem: Layout wrong if 'lines' changes while cmdline window is open. Solution: Do not restore the window layout if 'lines' changed. (closes #5130)
1 parent 5b41899 commit 1c329c0

6 files changed

Lines changed: 86 additions & 5 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
|0+0&#ffffff0| @73
2+
|[+1&&|N|o| |N|a|m|e|]| |[|+|]| @43|1|,|1| @11|T|o|p
3+
|0+0&&| @73
4+
|[+1&&|N|o| |N|a|m|e|]| |[|+|]| @43|1|,|1| @11|T|o|p
5+
|:+0#4040ff13&> +0#0000000&@73
6+
|~+0#4040ff13&| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
|~| @73
11+
|[+3#0000000&|C|o|m@1|a|n|d| |L|i|n|e|]| @42|1|,|0|-|1| @9|A|l@1
12+
|:+0&&| @73
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
>0+0&#ffffff0| @73
2+
|1| @73
3+
|[+3&&|N|o| |N|a|m|e|]| |[|+|]| @43|1|,|1| @11|T|o|p
4+
|0+0&&| @73
5+
|1| @73
6+
|2| @73
7+
|3| @73
8+
|4| @73
9+
|5| @73
10+
|6| @73
11+
|[+1&&|N|o| |N|a|m|e|]| |[|+|]| @43|1|,|1| @11|T|o|p
12+
| +0&&@74
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
>0+0&#ffffff0| @73
2+
|1| @73
3+
|2| @73
4+
|3| @73
5+
|4| @73
6+
|5| @73
7+
|6| @73
8+
|7| @73
9+
|8| @73
10+
|9| @73
11+
|1|0| @72
12+
|1@1| @72
13+
|1|2| @72
14+
|1|3| @72
15+
|1|4| @72
16+
|1|5| @72
17+
|1|6| @72
18+
@57|1|,|1| @10|T|o|p|

src/testdir/test_cmdline.vim

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,36 @@ func Test_cmdwin_bug()
768768
bw!
769769
endfunc
770770

771+
func Test_cmdwin_restore()
772+
CheckScreendump
773+
774+
let lines =<< trim [SCRIPT]
775+
call setline(1, range(30))
776+
2split
777+
[SCRIPT]
778+
call writefile(lines, 'XTest_restore')
779+
780+
let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
781+
call term_wait(buf, 100)
782+
call term_sendkeys(buf, "q:")
783+
call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
784+
785+
" normal restore
786+
call term_sendkeys(buf, ":q\<CR>")
787+
call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
788+
789+
" restore after setting 'lines' with one window
790+
call term_sendkeys(buf, ":close\<CR>")
791+
call term_sendkeys(buf, "q:")
792+
call term_sendkeys(buf, ":set lines=18\<CR>")
793+
call term_sendkeys(buf, ":q\<CR>")
794+
call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
795+
796+
" clean up
797+
call StopVimInTerminal(buf)
798+
call delete('XTest_restore')
799+
endfunc
800+
771801
func Test_buffers_lastused()
772802
" check that buffers are sorted by time when wildmode has lastused
773803
call test_settime(1550020000) " middle

src/version.c

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

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
2227,
744746
/**/
745747
2226,
746748
/**/

src/window.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5177,17 +5177,23 @@ win_size_save(garray_T *gap)
51775177
win_T *wp;
51785178

51795179
ga_init2(gap, (int)sizeof(int), 1);
5180-
if (ga_grow(gap, win_count() * 2) == OK)
5180+
if (ga_grow(gap, win_count() * 2 + 1) == OK)
5181+
{
5182+
// first entry is value of 'lines'
5183+
((int *)gap->ga_data)[gap->ga_len++] = Rows;
5184+
51815185
FOR_ALL_WINDOWS(wp)
51825186
{
51835187
((int *)gap->ga_data)[gap->ga_len++] =
51845188
wp->w_width + wp->w_vsep_width;
51855189
((int *)gap->ga_data)[gap->ga_len++] = wp->w_height;
51865190
}
5191+
}
51875192
}
51885193

51895194
/*
5190-
* Restore window sizes, but only if the number of windows is still the same.
5195+
* Restore window sizes, but only if the number of windows is still the same
5196+
* and 'lines' didn't change.
51915197
* Does not free the growarray.
51925198
*/
51935199
void
@@ -5196,13 +5202,14 @@ win_size_restore(garray_T *gap)
51965202
win_T *wp;
51975203
int i, j;
51985204

5199-
if (win_count() * 2 == gap->ga_len)
5205+
if (win_count() * 2 + 1 == gap->ga_len
5206+
&& ((int *)gap->ga_data)[0] == Rows)
52005207
{
52015208
/* The order matters, because frames contain other frames, but it's
52025209
* difficult to get right. The easy way out is to do it twice. */
52035210
for (j = 0; j < 2; ++j)
52045211
{
5205-
i = 0;
5212+
i = 1;
52065213
FOR_ALL_WINDOWS(wp)
52075214
{
52085215
frame_setwidth(wp->w_frame, ((int *)gap->ga_data)[i++]);
@@ -6374,7 +6381,7 @@ min_rows(void)
63746381
}
63756382

63766383
/*
6377-
* Return TRUE if there is only one window (in the current tab page), not
6384+
* Return TRUE if there is only one window and only one tab page, not
63786385
* counting a help or preview window, unless it is the current window.
63796386
* Does not count unlisted windows.
63806387
*/

0 commit comments

Comments
 (0)