]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0028: matchadd() conceal may use unrelated syntax cchar v9.2.0028
authorzeertzjq <zeertzjq@outlook.com>
Thu, 19 Feb 2026 16:42:09 +0000 (16:42 +0000)
committerChristian Brabandt <cb@256bit.org>
Thu, 19 Feb 2026 16:42:09 +0000 (16:42 +0000)
Problem:  matchadd() conceal may use unrelated syntax cchar.
Solution: Only use syntax cchar when syntax_flags has HL_CONCEAL
          (zeertzjq).

closes: #19459

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/drawline.c
src/testdir/test_matchadd_conceal.vim
src/version.c

index ef776dc204b6c3b0221bb9c7d0e4587f73d3abeb..e259e15e383353a246ba3b87b5ce09363aef8749 100644 (file)
@@ -3626,11 +3626,11 @@ win_line(
                && !(lnum_in_visual_area
                                    && vim_strchr(wp->w_p_cocu, 'v') == NULL))
            {
+               int syntax_conceal = (syntax_flags & HL_CONCEAL) != 0;
                wlv.char_attr = conceal_attr;
-               if (((prev_syntax_id != syntax_seqnr
-                                          && (syntax_flags & HL_CONCEAL) != 0)
+               if (((prev_syntax_id != syntax_seqnr && syntax_conceal)
                            || has_match_conc > 1)
-                       && (syn_get_sub_char() != NUL
+                       && ((syntax_conceal && syn_get_sub_char() != NUL)
                                || (has_match_conc && match_conc)
                                || wp->w_p_cole == 1)
                        && wp->w_p_cole != 3)
@@ -3639,7 +3639,7 @@ win_line(
                    // character.
                    if (has_match_conc && match_conc)
                        c = match_conc;
-                   else if (syn_get_sub_char() != NUL)
+                   else if (syntax_conceal && syn_get_sub_char() != NUL)
                        c = syn_get_sub_char();
                    else if (wp->w_lcs_chars.conceal != NUL)
                        c = wp->w_lcs_chars.conceal;
index 764e8c6e382de4a736a94bb5f3eefbc2d45e839d..b6917113b458a30968d36dd1da06156c31732673 100644 (file)
@@ -202,6 +202,29 @@ func Test_syn_and_match_conceal()
   call assert_equal(screenattr(lnum, 2), screenattr(lnum, 18))
   call assert_notequal(screenattr(lnum, 18), screenattr(lnum, 19))
 
+  5new | setlocal conceallevel=2 concealcursor=n
+  redraw!
+  call assert_equal(expect, Screenline(6 + lnum))
+
+  " Syntax conceal shouldn't interfere with matchadd() in another buffer.
+  call setline(1, 'foo bar baz')
+  call matchadd('Conceal', 'bar')
+  redraw!
+  call assert_equal('foo  baz', Screenline(1))
+  call assert_equal(expect, Screenline(6 + lnum))
+
+  " Syntax conceal shouldn't interfere with matchadd() in the same buffer.
+  syntax match MyOtherConceal /foo/ conceal cchar=!
+  redraw!
+  call assert_equal('!  baz', Screenline(1))
+  call assert_equal(expect, Screenline(6 + lnum))
+
+  syntax clear
+  redraw!
+  call assert_equal('foo  baz', Screenline(1))
+  call assert_equal(expect, Screenline(6 + lnum))
+  bwipe!
+
   "             123456789012345678
   let expect = '# ThisXis a Test'
   syntax clear MyConceal
index 4744ccf220fb367860f13db945d8a264c34729a5..84a2a8e69535a36c0efe614f08e29b8fbd3c5cd2 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    28,
 /**/
     27,
 /**/