]> granicus.if.org Git - vim/commitdiff
patch 8.0.1208: 'statusline' drops empty group with highlight change v8.0.1208
authorBram Moolenaar <Bram@vim.org>
Sun, 22 Oct 2017 12:22:16 +0000 (14:22 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 22 Oct 2017 12:22:16 +0000 (14:22 +0200)
Problem:    'statusline' drops empty group with highlight change.
Solution:   Do not drop an empty group if it changes highlighting. (Marius
            Gedminas, closes #2228)

src/buffer.c
src/testdir/test_statusline.vim
src/version.c

index 22effbb81f57fb38030d7bc6077a72826ed88e08..1bf692a83093c7472cbe8d02101bf91baa3b278b 100644 (file)
@@ -3883,6 +3883,8 @@ build_stl_str_hl(
     int                width;
     int                itemcnt;
     int                curitem;
+    int                group_end_userhl;
+    int                group_start_userhl;
     int                groupitem[STL_MAX_ITEM];
     int                groupdepth;
     struct stl_item
@@ -4023,11 +4025,20 @@ build_stl_str_hl(
            if (curitem > groupitem[groupdepth] + 1
                    && item[groupitem[groupdepth]].minwid == 0)
            {
-               /* remove group if all items are empty */
+               /* remove group if all items are empty and highlight group
+                * doesn't change */
+               group_start_userhl = group_end_userhl = 0;
+               for (n = 0; n < groupitem[groupdepth]; n++)
+                   if (item[n].type == Highlight)
+                       group_start_userhl = item[n].minwid;
                for (n = groupitem[groupdepth] + 1; n < curitem; n++)
-                   if (item[n].type == Normal || item[n].type == Highlight)
+               {
+                   if (item[n].type == Normal)
                        break;
-               if (n == curitem)
+                   if (item[n].type == Highlight)
+                       group_end_userhl = item[n].minwid;
+               }
+               if (n == curitem && group_start_userhl == group_end_userhl)
                {
                    p = t;
                    l = 0;
index 351b119acd314b3dc9924bee88ff4bf867894ce3..de943f24666f1fa6be8cef33d54401ecea0a0fa6 100644 (file)
@@ -5,7 +5,6 @@
 "   %N
 "   %T
 "   %X
-"   %*
 
 source view_util.vim
 
@@ -249,6 +248,70 @@ func Test_statusline()
   call assert_equal(sa1, sa3)
   call assert_notequal(sa1, sa2)
 
+  " An empty group that contains highlight changes
+  let g:a = ''
+  set statusline=ab%(cd%1*%{g:a}%*%)de
+  call assert_match('^abde\s*$', s:get_statusline())
+  let sa1=screenattr(&lines - 1, 1)
+  let sa2=screenattr(&lines - 1, 4)
+  call assert_equal(sa1, sa2)
+  let g:a = 'X'
+  call assert_match('^abcdXde\s*$', s:get_statusline())
+  let sa1=screenattr(&lines - 1, 1)
+  let sa2=screenattr(&lines - 1, 5)
+  let sa3=screenattr(&lines - 1, 7)
+  call assert_equal(sa1, sa3)
+  call assert_notequal(sa1, sa2)
+
+  let g:a = ''
+  set statusline=ab%1*%(cd%*%{g:a}%1*%)de
+  call assert_match('^abde\s*$', s:get_statusline())
+  let sa1=screenattr(&lines - 1, 1)
+  let sa2=screenattr(&lines - 1, 4)
+  call assert_notequal(sa1, sa2)
+  let g:a = 'X'
+  call assert_match('^abcdXde\s*$', s:get_statusline())
+  let sa1=screenattr(&lines - 1, 1)
+  let sa2=screenattr(&lines - 1, 3)
+  let sa3=screenattr(&lines - 1, 5)
+  let sa4=screenattr(&lines - 1, 7)
+  call assert_notequal(sa1, sa2)
+  call assert_equal(sa1, sa3)
+  call assert_equal(sa2, sa4)
+
+  " An empty group that contains highlight changes and doesn't reset them
+  let g:a = ''
+  set statusline=ab%(cd%1*%{g:a}%)de
+  call assert_match('^abcdde\s*$', s:get_statusline())
+  let sa1=screenattr(&lines - 1, 1)
+  let sa2=screenattr(&lines - 1, 5)
+  call assert_notequal(sa1, sa2)
+  let g:a = 'X'
+  call assert_match('^abcdXde\s*$', s:get_statusline())
+  let sa1=screenattr(&lines - 1, 1)
+  let sa2=screenattr(&lines - 1, 5)
+  let sa3=screenattr(&lines - 1, 7)
+  call assert_notequal(sa1, sa2)
+  call assert_equal(sa2, sa3)
+
+  let g:a = ''
+  set statusline=ab%1*%(cd%*%{g:a}%)de
+  call assert_match('^abcdde\s*$', s:get_statusline())
+  let sa1=screenattr(&lines - 1, 1)
+  let sa2=screenattr(&lines - 1, 3)
+  let sa3=screenattr(&lines - 1, 5)
+  call assert_notequal(sa1, sa2)
+  call assert_equal(sa1, sa3)
+  let g:a = 'X'
+  call assert_match('^abcdXde\s*$', s:get_statusline())
+  let sa1=screenattr(&lines - 1, 1)
+  let sa2=screenattr(&lines - 1, 3)
+  let sa3=screenattr(&lines - 1, 5)
+  let sa4=screenattr(&lines - 1, 7)
+  call assert_notequal(sa1, sa2)
+  call assert_equal(sa1, sa3)
+  call assert_equal(sa1, sa4)
+
   " %%: a percent sign.
   set statusline=10%%
   call assert_match('^10%\s*$', s:get_statusline())
index 040d32466bf44f98edb9f4c061fd31bf12ca76d9..d9a3fdb0a08de2f6c8d7d883efa4a48afc63b7f1 100644 (file)
@@ -761,6 +761,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1208,
 /**/
     1207,
 /**/