]> granicus.if.org Git - vim/commitdiff
patch 8.2.1056: wrong display when mixing match conceal and syntax conceal v8.2.1056
authorBram Moolenaar <Bram@vim.org>
Thu, 25 Jun 2020 18:07:04 +0000 (20:07 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 25 Jun 2020 18:07:04 +0000 (20:07 +0200)
Problem:    Wrong display when mixing match conceal and syntax conceal.
Solution:   Adjust how conceal flags are used. (closes #6327, closes #6303)

src/drawline.c
src/highlight.c
src/testdir/test_matchadd_conceal.vim
src/version.c

index 6d14bda7b6ab9306973ab6c79861b2f500fe5e88..fad0645fe86690ffe228d1d61ad56fc85743d618 100644 (file)
@@ -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();
index dacce5c497db4d98bbd741953735ce90148444e8..8c41c38fc8fb47ca8ed311911538174e4e298415 100644 (file)
@@ -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;
index be154643e66b9eda2c669ab22263d04d504fb79f..6f6e21694c60e209562957712f2f2dcdd3231e1c 100644 (file)
@@ -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,29 @@ 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
+  hi MyConceal ctermbg=4 ctermfg=2
+  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))
+
+  syntax clear MyConceal
   syntax match MyConceal /\%2l / conceal containedin=ALL cchar=*
   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 +169,8 @@ 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'
+  "             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
index 11ec7637e6a2b62eae276e08fb3907edaa96de4a..90a523e3f57eae348ccb61824de64c776523e4a8 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1056,
 /**/
     1055,
 /**/