vim-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 vim/vim#6327, closes vim/vim#6303)
211dd3fd82
This commit is contained in:
Jan Edmund Lazo
2021-02-13 16:23:31 -05:00
parent 34291eba80
commit fd44bd4d4f
2 changed files with 104 additions and 47 deletions

View File

@@ -2082,7 +2082,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
int line_attr_lowprio = 0; // low-priority attribute for the line int line_attr_lowprio = 0; // low-priority attribute for the line
matchitem_T *cur; // points to the match list matchitem_T *cur; // points to the match list
match_T *shl; // points to search_hl or a match match_T *shl; // points to search_hl or a match
int shl_flag; // flag to indicate whether search_hl bool shl_flag; // flag to indicate whether search_hl
// has been processed or not // has been processed or not
bool prevcol_hl_flag; // flag to indicate whether prevcol bool prevcol_hl_flag; // flag to indicate whether prevcol
// equals startcol of search_hl or one // equals startcol of search_hl or one
@@ -2950,16 +2950,15 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
*/ */
v = (long)(ptr - line); v = (long)(ptr - line);
cur = wp->w_match_head; cur = wp->w_match_head;
shl_flag = FALSE; shl_flag = false;
while (cur != NULL || shl_flag == FALSE) { while (cur != NULL || !shl_flag) {
if (shl_flag == FALSE if (!shl_flag
&& ((cur != NULL && (cur == NULL || cur->priority > SEARCH_HL_PRIORITY)) {
&& cur->priority > SEARCH_HL_PRIORITY)
|| cur == NULL)) {
shl = &search_hl; shl = &search_hl;
shl_flag = TRUE; shl_flag = true;
} else } else {
shl = &cur->hl; shl = &cur->hl;
}
if (cur != NULL) { if (cur != NULL) {
cur->pos.cur = 0; cur->pos.cur = 0;
} }
@@ -2984,7 +2983,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
has_match_conc = v == (long)shl->startcol ? 2 : 1; has_match_conc = v == (long)shl->startcol ? 2 : 1;
match_conc = cur->conceal_char; match_conc = cur->conceal_char;
} else { } else {
has_match_conc = match_conc = 0; has_match_conc = 0;
} }
} else if (v == (long)shl->endcol) { } else if (v == (long)shl->endcol) {
shl->attr_cur = 0; shl->attr_cur = 0;
@@ -3026,16 +3025,15 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
search_attr_from_match = false; search_attr_from_match = false;
search_attr = search_hl.attr_cur; search_attr = search_hl.attr_cur;
cur = wp->w_match_head; cur = wp->w_match_head;
shl_flag = FALSE; shl_flag = false;
while (cur != NULL || shl_flag == FALSE) { while (cur != NULL || !shl_flag) {
if (shl_flag == FALSE if (!shl_flag
&& ((cur != NULL && (cur == NULL || cur->priority > SEARCH_HL_PRIORITY)) {
&& cur->priority > SEARCH_HL_PRIORITY)
|| cur == NULL)) {
shl = &search_hl; shl = &search_hl;
shl_flag = TRUE; shl_flag = true;
} else } else {
shl = &cur->hl; shl = &cur->hl;
}
if (shl->attr_cur != 0) { if (shl->attr_cur != 0) {
search_attr = shl->attr_cur; search_attr = shl->attr_cur;
search_attr_from_match = shl != &search_hl; search_attr_from_match = shl != &search_hl;
@@ -3678,12 +3676,13 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
&& vim_strchr(wp->w_p_cocu, 'v') == NULL)) { && vim_strchr(wp->w_p_cocu, 'v') == NULL)) {
char_attr = conceal_attr; char_attr = conceal_attr;
if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1) if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
&& (syn_get_sub_char() != NUL || match_conc && (syn_get_sub_char() != NUL
|| (has_match_conc && match_conc)
|| wp->w_p_cole == 1) || wp->w_p_cole == 1)
&& wp->w_p_cole != 3) { && wp->w_p_cole != 3) {
// First time at this concealed item: display one // First time at this concealed item: display one
// character. // character.
if (match_conc) { if (has_match_conc && match_conc) {
c = match_conc; c = match_conc;
} else if (syn_get_sub_char() != NUL) { } else if (syn_get_sub_char() != NUL) {
c = syn_get_sub_char(); c = syn_get_sub_char();
@@ -3843,16 +3842,15 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
// 'search_hl' and the match list. // 'search_hl' and the match list.
char_attr = search_hl.attr; char_attr = search_hl.attr;
cur = wp->w_match_head; cur = wp->w_match_head;
shl_flag = FALSE; shl_flag = false;
while (cur != NULL || shl_flag == FALSE) { while (cur != NULL || !shl_flag) {
if (shl_flag == FALSE if (!shl_flag
&& ((cur != NULL && (cur == NULL || cur->priority > SEARCH_HL_PRIORITY)) {
&& cur->priority > SEARCH_HL_PRIORITY)
|| cur == NULL)) {
shl = &search_hl; shl = &search_hl;
shl_flag = TRUE; shl_flag = true;
} else } else {
shl = &cur->hl; shl = &cur->hl;
}
if ((ptr - line) - 1 == (long)shl->startcol if ((ptr - line) - 1 == (long)shl->startcol
&& (shl == &search_hl || !shl->is_addpos)) { && (shl == &search_hl || !shl->is_addpos)) {
char_attr = shl->attr; char_attr = shl->attr;

View File

@@ -59,9 +59,9 @@ func Test_matchadd_and_conceallevel_3()
setlocal filetype=conf setlocal filetype=conf
syntax on syntax on
1put='# This is a Test' 1put='# This is a Test $'
" 1234567890123456 " 1234567890123
let expect = '#ThisisaTest' let expect = '#ThisisaTest$'
call cursor(1, 1) call cursor(1, 1)
call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'}) call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'})
@@ -69,22 +69,25 @@ func Test_matchadd_and_conceallevel_3()
let lnum = 2 let lnum = 2
call assert_equal(expect, Screenline(lnum)) call assert_equal(expect, Screenline(lnum))
call assert_equal(screenattr(lnum, 1), screenattr(lnum, 2)) 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_equal(screenattr(lnum, 2), screenattr(lnum, 10)) call assert_equal(screenattr(lnum, 1), screenattr(lnum, 10))
call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) 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)) call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 16))
" more matchadd() " more matchadd()
" 1234567890123456 " 12345678901234
let expect = '#Thisisa Test' let expect = '#Thisisa Test$'
call matchadd('ErrorMsg', '\%2l Test', 20, -1, {'conceal': 'X'}) call matchadd('ErrorMsg', '\%2l Test', 20, -1, {'conceal': 'X'})
redraw! redraw!
call assert_equal(expect, Screenline(lnum)) call assert_equal(expect, Screenline(lnum))
call assert_equal(screenattr(lnum, 1) , screenattr(lnum, 2)) 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_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, 1) , screenattr(lnum, 16))
call assert_notequal(screenattr(lnum, 10), screenattr(lnum, 16)) call assert_notequal(screenattr(lnum, 10), screenattr(lnum, 16))
@@ -133,14 +136,17 @@ func Test_syn_and_match_conceal()
setlocal concealcursor=n conceallevel=1 setlocal concealcursor=n conceallevel=1
1put='# This is a Test ' 1put='# This is a Test '
" 1234567890123456
let expect = '#ZThisZisZaZTest'
call cursor(1, 1)
call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'})
syntax match MyConceal /\%2l / conceal containedin=ALL cchar=*
redraw!
let lnum = 2 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_equal(expect, Screenline(lnum))
call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2)) 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, 7))
@@ -148,8 +154,19 @@ func Test_syn_and_match_conceal()
call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12))
call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16)) call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16))
" 1234567890123456 syntax clear MyConceal
let expect = '#*This*is*a*Test' 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() call clearmatches()
redraw! redraw!
@@ -160,6 +177,48 @@ func Test_syn_and_match_conceal()
call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12))
call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16)) 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 syntax off
quit! quit!
endfunc endfunc