changeset 21010:ca2e18364888 v8.2.1056

patch 8.2.1056: wrong display when mixing match conceal and syntax conceal Commit: https://github.com/vim/vim/commit/211dd3fd82216ca879fe7f917ea345b3ae366ce1 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jun 25 20:07:04 2020 +0200 patch 8.2.1056: wrong display when mixing match conceal and syntax conceal Problem: Wrong display when mixing match conceal and syntax conceal. Solution: Adjust how conceal flags are used. (closes https://github.com/vim/vim/issues/6327, closes https://github.com/vim/vim/issues/6303)
author Bram Moolenaar <Bram@vim.org>
date Thu, 25 Jun 2020 20:15:32 +0200
parents 0ee88eb11343
children 79651004e6df
files src/drawline.c src/highlight.c src/testdir/test_matchadd_conceal.vim src/version.c
diffstat 4 files changed, 88 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/drawline.c
+++ b/src/drawline.c
@@ -967,7 +967,7 @@ win_line(
     for (;;)
     {
 #if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
-	int has_match_conc  = 0;	// match wants to conceal
+	int has_match_conc = 0;	// match wants to conceal
 #endif
 #ifdef FEAT_CONCEAL
 	int did_decrement_ptr = FALSE;
@@ -2353,13 +2353,14 @@ win_line(
 	    {
 		char_attr = conceal_attr;
 		if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
-			&& (syn_get_sub_char() != NUL || match_conc
-							 || wp->w_p_cole == 1)
+			&& (syn_get_sub_char() != NUL
+				|| (has_match_conc && match_conc)
+				|| wp->w_p_cole == 1)
 			&& wp->w_p_cole != 3)
 		{
 		    // First time at this concealed item: display one
 		    // character.
-		    if (match_conc)
+		    if (has_match_conc && match_conc)
 			c = match_conc;
 		    else if (syn_get_sub_char() != NUL)
 			c = syn_get_sub_char();
--- a/src/highlight.c
+++ b/src/highlight.c
@@ -4419,9 +4419,8 @@ update_search_hl(
     while (cur != NULL || shl_flag == FALSE)
     {
 	if (shl_flag == FALSE
-		&& ((cur != NULL
-			&& cur->priority > SEARCH_HL_PRIORITY)
-		    || cur == NULL))
+		&& (cur == NULL
+			|| cur->priority > SEARCH_HL_PRIORITY))
 	{
 	    shl = search_hl;
 	    shl_flag = TRUE;
@@ -4453,7 +4452,7 @@ update_search_hl(
 		    *match_conc = cur->conceal_char;
 		}
 		else
-		    *has_match_conc = *match_conc = 0;
+		    *has_match_conc = 0;
 # endif
 	    }
 	    else if (col == shl->endcol)
@@ -4503,9 +4502,8 @@ update_search_hl(
     while (cur != NULL || shl_flag == FALSE)
     {
 	if (shl_flag == FALSE
-		&& ((cur != NULL
-			&& cur->priority > SEARCH_HL_PRIORITY)
-		    || cur == NULL))
+		&& (cur == NULL ||
+			cur->priority > SEARCH_HL_PRIORITY))
 	{
 	    shl = search_hl;
 	    shl_flag = TRUE;
--- a/src/testdir/test_matchadd_conceal.vim
+++ b/src/testdir/test_matchadd_conceal.vim
@@ -63,9 +63,9 @@ func Test_matchadd_and_conceallevel_3()
   setlocal filetype=conf
   syntax on
 
-  1put='# This is a Test'
-  "             1234567890123456
-  let expect = '#ThisisaTest'
+  1put='# This is a Test  $'
+  "             1234567890123
+  let expect = '#ThisisaTest$'
 
   call cursor(1, 1)
   call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'})
@@ -73,22 +73,25 @@ func Test_matchadd_and_conceallevel_3()
   let lnum = 2
   call assert_equal(expect, Screenline(lnum))
   call assert_equal(screenattr(lnum, 1), screenattr(lnum, 2))
-  call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7))
-  call assert_equal(screenattr(lnum, 2), screenattr(lnum, 10))
-  call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12))
+  call assert_equal(screenattr(lnum, 1), screenattr(lnum, 7))
+  call assert_equal(screenattr(lnum, 1), screenattr(lnum, 10))
+  call assert_equal(screenattr(lnum, 1), screenattr(lnum, 12))
+  call assert_equal(screenattr(lnum, 1), screenattr(lnum, 13))
+  call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 14))
   call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 16))
 
   " more matchadd()
-  "             1234567890123456
-  let expect = '#Thisisa Test'
+  "             12345678901234
+  let expect = '#Thisisa Test$'
 
   call matchadd('ErrorMsg', '\%2l Test', 20, -1, {'conceal': 'X'})
   redraw!
   call assert_equal(expect, Screenline(lnum))
   call assert_equal(screenattr(lnum, 1) , screenattr(lnum, 2))
-  call assert_equal(screenattr(lnum, 2) , screenattr(lnum, 7))
+  call assert_equal(screenattr(lnum, 1) , screenattr(lnum, 7))
   call assert_notequal(screenattr(lnum, 1) , screenattr(lnum, 10))
-  call assert_equal(screenattr(lnum, 10), screenattr(lnum, 12))
+  call assert_equal(screenattr(lnum, 10), screenattr(lnum, 13))
+  call assert_equal(screenattr(lnum, 1), screenattr(lnum, 14))
   call assert_notequal(screenattr(lnum, 1) , screenattr(lnum, 16))
   call assert_notequal(screenattr(lnum, 10), screenattr(lnum, 16))
 
@@ -136,15 +139,18 @@ func Test_syn_and_match_conceal()
   new
   setlocal concealcursor=n conceallevel=1
 
-  1put='# This is a Test'
-  "             1234567890123456
-  let expect = '#ZThisZisZaZTest'
+  1put='# This is a Test  '
 
+  let lnum = 2
   call cursor(1, 1)
+
+  "             123456789012345678
+  let expect = '#ZThisZisZaZTestZZ'
   call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'})
-  syntax match MyConceal /\%2l / conceal containedin=ALL cchar=*
+  syntax match MyConceal /\%2l / conceal containedin=ALL
+  hi MyConceal ctermbg=4 ctermfg=2
   redraw!
-  let lnum = 2
+
   call assert_equal(expect, Screenline(lnum))
   call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2))
   call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7))
@@ -152,8 +158,19 @@ func Test_syn_and_match_conceal()
   call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12))
   call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16))
 
-  "             1234567890123456
-  let expect = '#*This*is*a*Test'
+  syntax clear MyConceal
+  syntax match MyConceal /\%2l / conceal containedin=ALL cchar=*
+  redraw!
+
+  call assert_equal(expect, Screenline(lnum))
+  call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2))
+  call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7))
+  call assert_equal(screenattr(lnum, 2), screenattr(lnum, 10))
+  call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12))
+  call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16))
+
+  "             123456789012345678
+  let expect = '#*This*is*a*Test**'
   call clearmatches()
   redraw!
 
@@ -164,6 +181,48 @@ func Test_syn_and_match_conceal()
   call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12))
   call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16))
 
+  "             123456789012345678
+  let expect = '#*ThisXis*a*Test**'
+  call matchadd('Conceal', '\%2l\%7c ', 10, -1, {'conceal': 'X'})
+  redraw!
+
+  call assert_equal(expect, Screenline(lnum))
+  call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2))
+  call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7))
+  call assert_equal(screenattr(lnum, 2), screenattr(lnum, 10))
+  call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12))
+  call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16))
+
+  "             123456789012345678
+  let expect = '#*ThisXis*a*Test**'
+  call matchadd('ErrorMsg', '\%2l Test', 20, -1)
+  redraw!
+
+  call assert_equal(expect, Screenline(lnum))
+  call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2))
+  call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12))
+  call assert_notequal(screenattr(lnum, 12), screenattr(lnum, 13))
+  call assert_equal(screenattr(lnum, 13), screenattr(lnum, 16))
+  call assert_equal(screenattr(lnum, 2), screenattr(lnum, 17))
+  call assert_equal(screenattr(lnum, 2), screenattr(lnum, 18))
+  call assert_notequal(screenattr(lnum, 18), screenattr(lnum, 19))
+
+  "             123456789012345678
+  let expect = '# ThisXis a Test'
+  syntax clear MyConceal
+  syntax match MyConceal /\%2l / conceal containedin=ALL
+  redraw!
+
+  call assert_equal(expect, Screenline(lnum))
+  call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2))
+  call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12))
+  call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 12))
+  call assert_notequal(screenattr(lnum, 12), screenattr(lnum, 13))
+  call assert_equal(screenattr(lnum, 13), screenattr(lnum, 16))
+  call assert_equal(screenattr(lnum, 2), screenattr(lnum, 17))
+  call assert_equal(screenattr(lnum, 2), screenattr(lnum, 18))
+  call assert_notequal(screenattr(lnum, 18), screenattr(lnum, 19))
+
   syntax off
   quit!
 endfunc
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1056,
+/**/
     1055,
 /**/
     1054,