Skip to content

Commit 6b89dbb

Browse files
committed
patch 8.0.1208: 'statusline' drops empty group with highlight change
Problem: 'statusline' drops empty group with highlight change. Solution: Do not drop an empty group if it changes highlighting. (Marius Gedminas, closes #2228)
1 parent 67435d9 commit 6b89dbb

3 files changed

Lines changed: 80 additions & 4 deletions

File tree

src/buffer.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3883,6 +3883,8 @@ build_stl_str_hl(
38833883
int width;
38843884
int itemcnt;
38853885
int curitem;
3886+
int group_end_userhl;
3887+
int group_start_userhl;
38863888
int groupitem[STL_MAX_ITEM];
38873889
int groupdepth;
38883890
struct stl_item
@@ -4023,11 +4025,20 @@ build_stl_str_hl(
40234025
if (curitem > groupitem[groupdepth] + 1
40244026
&& item[groupitem[groupdepth]].minwid == 0)
40254027
{
4026-
/* remove group if all items are empty */
4028+
/* remove group if all items are empty and highlight group
4029+
* doesn't change */
4030+
group_start_userhl = group_end_userhl = 0;
4031+
for (n = 0; n < groupitem[groupdepth]; n++)
4032+
if (item[n].type == Highlight)
4033+
group_start_userhl = item[n].minwid;
40274034
for (n = groupitem[groupdepth] + 1; n < curitem; n++)
4028-
if (item[n].type == Normal || item[n].type == Highlight)
4035+
{
4036+
if (item[n].type == Normal)
40294037
break;
4030-
if (n == curitem)
4038+
if (item[n].type == Highlight)
4039+
group_end_userhl = item[n].minwid;
4040+
}
4041+
if (n == curitem && group_start_userhl == group_end_userhl)
40314042
{
40324043
p = t;
40334044
l = 0;

src/testdir/test_statusline.vim

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
" %N
66
" %T
77
" %X
8-
" %*
98

109
source view_util.vim
1110

@@ -249,6 +248,70 @@ func Test_statusline()
249248
call assert_equal(sa1, sa3)
250249
call assert_notequal(sa1, sa2)
251250

251+
" An empty group that contains highlight changes
252+
let g:a = ''
253+
set statusline=ab%(cd%1*%{g:a}%*%)de
254+
call assert_match('^abde\s*$', s:get_statusline())
255+
let sa1=screenattr(&lines - 1, 1)
256+
let sa2=screenattr(&lines - 1, 4)
257+
call assert_equal(sa1, sa2)
258+
let g:a = 'X'
259+
call assert_match('^abcdXde\s*$', s:get_statusline())
260+
let sa1=screenattr(&lines - 1, 1)
261+
let sa2=screenattr(&lines - 1, 5)
262+
let sa3=screenattr(&lines - 1, 7)
263+
call assert_equal(sa1, sa3)
264+
call assert_notequal(sa1, sa2)
265+
266+
let g:a = ''
267+
set statusline=ab%1*%(cd%*%{g:a}%1*%)de
268+
call assert_match('^abde\s*$', s:get_statusline())
269+
let sa1=screenattr(&lines - 1, 1)
270+
let sa2=screenattr(&lines - 1, 4)
271+
call assert_notequal(sa1, sa2)
272+
let g:a = 'X'
273+
call assert_match('^abcdXde\s*$', s:get_statusline())
274+
let sa1=screenattr(&lines - 1, 1)
275+
let sa2=screenattr(&lines - 1, 3)
276+
let sa3=screenattr(&lines - 1, 5)
277+
let sa4=screenattr(&lines - 1, 7)
278+
call assert_notequal(sa1, sa2)
279+
call assert_equal(sa1, sa3)
280+
call assert_equal(sa2, sa4)
281+
282+
" An empty group that contains highlight changes and doesn't reset them
283+
let g:a = ''
284+
set statusline=ab%(cd%1*%{g:a}%)de
285+
call assert_match('^abcdde\s*$', s:get_statusline())
286+
let sa1=screenattr(&lines - 1, 1)
287+
let sa2=screenattr(&lines - 1, 5)
288+
call assert_notequal(sa1, sa2)
289+
let g:a = 'X'
290+
call assert_match('^abcdXde\s*$', s:get_statusline())
291+
let sa1=screenattr(&lines - 1, 1)
292+
let sa2=screenattr(&lines - 1, 5)
293+
let sa3=screenattr(&lines - 1, 7)
294+
call assert_notequal(sa1, sa2)
295+
call assert_equal(sa2, sa3)
296+
297+
let g:a = ''
298+
set statusline=ab%1*%(cd%*%{g:a}%)de
299+
call assert_match('^abcdde\s*$', s:get_statusline())
300+
let sa1=screenattr(&lines - 1, 1)
301+
let sa2=screenattr(&lines - 1, 3)
302+
let sa3=screenattr(&lines - 1, 5)
303+
call assert_notequal(sa1, sa2)
304+
call assert_equal(sa1, sa3)
305+
let g:a = 'X'
306+
call assert_match('^abcdXde\s*$', s:get_statusline())
307+
let sa1=screenattr(&lines - 1, 1)
308+
let sa2=screenattr(&lines - 1, 3)
309+
let sa3=screenattr(&lines - 1, 5)
310+
let sa4=screenattr(&lines - 1, 7)
311+
call assert_notequal(sa1, sa2)
312+
call assert_equal(sa1, sa3)
313+
call assert_equal(sa1, sa4)
314+
252315
" %%: a percent sign.
253316
set statusline=10%%
254317
call assert_match('^10%\s*$', s:get_statusline())

src/version.c

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

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1208,
764766
/**/
765767
1207,
766768
/**/

0 commit comments

Comments
 (0)