aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/screen.c14
-rw-r--r--src/nvim/testdir/Makefile1
-rw-r--r--src/nvim/testdir/test_alot.vim1
-rw-r--r--src/nvim/testdir/test_matchadd_conceal.vim262
-rw-r--r--src/nvim/testdir/test_matchadd_conceal_utf8.vim39
-rw-r--r--src/nvim/version.c2
6 files changed, 311 insertions, 8 deletions
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 9a2eeda8b2..47dd640e59 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -2210,8 +2210,8 @@ win_line (
///< force wrapping
int vcol_off = 0; ///< offset for concealed characters
int did_wcol = false;
- int match_conc = false; ///< cchar for match functions
- int has_match_conc = false; ///< match wants to conceal
+ int match_conc = 0; ///< cchar for match functions
+ int has_match_conc = 0; ///< match wants to conceal
int old_boguscols = 0;
# define VCOL_HLC (vcol - vcol_off)
# define FIX_FOR_BOGUSCOLS \
@@ -2656,7 +2656,7 @@ win_line (
// Repeat for the whole displayed line.
for (;; ) {
- has_match_conc = false;
+ has_match_conc = 0;
// Skip this quickly when working on the text.
if (draw_state != WL_LINE) {
if (draw_state == WL_CMDLINE - 1 && n_extra == 0) {
@@ -2906,10 +2906,10 @@ win_line (
shl->attr_cur = shl->attr;
if (cur != NULL && syn_name2id((char_u *)"Conceal")
== cur->hlg_id) {
- has_match_conc = true;
+ has_match_conc = v == (long)shl->startcol ? 2 : 1;
match_conc = cur->conceal_char;
} else {
- has_match_conc = match_conc = false;
+ has_match_conc = match_conc = 0;
}
} else if (v == (long)shl->endcol) {
shl->attr_cur = 0;
@@ -3633,11 +3633,11 @@ win_line (
if (wp->w_p_cole > 0
&& (wp != curwin || lnum != wp->w_cursor.lnum
|| conceal_cursor_line(wp))
- && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc)
+ && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
&& !(lnum_in_visual_area
&& vim_strchr(wp->w_p_cocu, 'v') == NULL)) {
char_attr = conceal_attr;
- if (prev_syntax_id != syntax_seqnr
+ if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
&& (syn_get_sub_char() != NUL || match_conc
|| wp->w_p_cole == 1)
&& wp->w_p_cole != 3) {
diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile
index 10d26bd8cf..4d21887240 100644
--- a/src/nvim/testdir/Makefile
+++ b/src/nvim/testdir/Makefile
@@ -41,6 +41,7 @@ NEW_TESTS = \
test_viml.res \
test_visual.res \
test_window_id.res \
+ test_matchadd_conceal.res \
test_alot.res
SCRIPTS_GUI := test16.out
diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim
index f0efd6e4ed..0a4aa1dc50 100644
--- a/src/nvim/testdir/test_alot.vim
+++ b/src/nvim/testdir/test_alot.vim
@@ -10,3 +10,4 @@ source test_popup.vim
source test_regexp_utf8.vim
source test_syn_attr.vim
source test_unlet.vim
+source test_matchadd_conceal_utf8.vim
diff --git a/src/nvim/testdir/test_matchadd_conceal.vim b/src/nvim/testdir/test_matchadd_conceal.vim
new file mode 100644
index 0000000000..bc1c28d6e9
--- /dev/null
+++ b/src/nvim/testdir/test_matchadd_conceal.vim
@@ -0,0 +1,262 @@
+" Test for matchadd() and conceal feature
+if !has('conceal')
+ finish
+endif
+
+function! s:screenline(lnum) abort
+ let line = []
+ for c in range(1, winwidth(0))
+ call add(line, nr2char(screenchar(a:lnum, c)))
+ endfor
+ return s:trim(join(line, ''))
+endfunction
+
+function! s:trim(str) abort
+ return matchstr(a:str,'^\s*\zs.\{-}\ze\s*$')
+endfunction
+
+function! Test_simple_matchadd()
+ new
+
+ 1put='# This is a Test'
+ " 1234567890123456
+ let expect = '# This is a Test'
+
+ call cursor(1, 1)
+ call matchadd('Conceal', '\%2l ')
+ redraw!
+ let lnum = 2
+ call assert_equal(expect, s: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, 10))
+ call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12))
+ call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16))
+
+ quit!
+endfunction
+
+function! Test_simple_matchadd_and_conceal()
+ new
+ setlocal concealcursor=n conceallevel=1
+
+ 1put='# This is a Test'
+ " 1234567890123456
+ let expect = '#XThisXisXaXTest'
+
+ call cursor(1, 1)
+ call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'})
+ redraw!
+ let lnum = 2
+ call assert_equal(expect, s: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))
+
+ quit!
+endfunction
+
+function! Test_matchadd_and_conceallevel_3()
+ new
+
+ setlocal conceallevel=3
+ " set filetype and :syntax on to change screenattr()
+ setlocal filetype=conf
+ syntax on
+
+ 1put='# This is a Test'
+ " 1234567890123456
+ let expect = '#ThisisaTest'
+
+ call cursor(1, 1)
+ call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'})
+ redraw!
+ let lnum = 2
+ call assert_equal(expect, s: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_notequal(screenattr(lnum, 1), screenattr(lnum, 16))
+
+ " more matchadd()
+ " 1234567890123456
+ let expect = '#Thisisa Test'
+
+ call matchadd('ErrorMsg', '\%2l Test', 20, -1, {'conceal': 'X'})
+ redraw!
+ call assert_equal(expect, s:screenline(lnum))
+ call assert_equal(screenattr(lnum, 1) , screenattr(lnum, 2))
+ call assert_equal(screenattr(lnum, 2) , screenattr(lnum, 7))
+ call assert_notequal(screenattr(lnum, 1) , screenattr(lnum, 10))
+ call assert_equal(screenattr(lnum, 10), screenattr(lnum, 12))
+ call assert_notequal(screenattr(lnum, 1) , screenattr(lnum, 16))
+ call assert_notequal(screenattr(lnum, 10), screenattr(lnum, 16))
+
+ syntax off
+ quit!
+endfunction
+
+function! Test_default_conceal_char()
+ new
+ setlocal concealcursor=n conceallevel=1
+
+ 1put='# This is a Test'
+ " 1234567890123456
+ let expect = '# This is a Test'
+
+ call cursor(1, 1)
+ call matchadd('Conceal', '\%2l ', 10, -1, {})
+ redraw!
+ let lnum = 2
+ call assert_equal(expect, s: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))
+
+ " 1234567890123456
+ let expect = '#+This+is+a+Test'
+ let listchars_save = &listchars
+ set listchars=conceal:+
+ redraw!
+
+ call assert_equal(expect, s: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))
+
+ let &listchars = listchars_save
+ quit!
+endfunction
+
+function! Test_syn_and_match_conceal()
+ new
+ setlocal concealcursor=n conceallevel=1
+
+ 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
+ call assert_equal(expect, s: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))
+
+ " 1234567890123456
+ let expect = '#*This*is*a*Test'
+ call clearmatches()
+ redraw!
+
+ call assert_equal(expect, s: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 off
+ quit!
+endfunction
+
+function! Test_clearmatches()
+ new
+ setlocal concealcursor=n conceallevel=1
+
+ 1put='# This is a Test'
+ " 1234567890123456
+ let expect = '# This is a Test'
+
+ call cursor(1, 1)
+ call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'})
+ let a = getmatches()
+ call clearmatches()
+ redraw!
+
+ let lnum = 2
+ call assert_equal(expect, s: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, 16))
+
+ " reset match using setmatches()
+ " 1234567890123456
+ let expect = '#ZThisZisZaZTest'
+ call setmatches(a)
+ redraw!
+
+ call assert_equal(expect, s: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))
+ call assert_equal({'group': 'Conceal', 'pattern': '\%2l ', 'priority': 10, 'id': a[0].id, 'conceal': 'Z'}, a[0])
+
+ quit!
+endfunction
+
+function! Test_using_matchaddpos()
+ new
+ setlocal concealcursor=n conceallevel=1
+ " set filetype and :syntax on to change screenattr()
+ setlocal filetype=conf
+ syntax on
+
+ 1put='# This is a Test'
+ " 1234567890123456
+ let expect = '#Pis a Test'
+
+ call cursor(1, 1)
+ call matchaddpos('Conceal', [[2,2,6]], 10, -1, {'conceal': 'P'})
+ let a = getmatches()
+ redraw!
+
+ let lnum = 2
+ call assert_equal(expect, s:screenline(lnum))
+ call assert_notequal(screenattr(lnum, 1) , screenattr(lnum, 2))
+ call assert_notequal(screenattr(lnum, 2) , screenattr(lnum, 7))
+ call assert_equal(screenattr(lnum, 1) , screenattr(lnum, 7))
+ call assert_equal(screenattr(lnum, 1) , screenattr(lnum, 10))
+ call assert_notequal(screenattr(lnum, 1) , screenattr(lnum, 12))
+ call assert_notequal(screenattr(lnum, 1) , screenattr(lnum, 16))
+ call assert_equal(screenattr(lnum, 12), screenattr(lnum, 16))
+ call assert_equal({'group': 'Conceal', 'id': a[0].id, 'priority': 10, 'pos1': [2, 2, 6], 'conceal': 'P'}, a[0])
+
+ syntax off
+ quit!
+endfunction
+
+function! Test_matchadd_repeat_conceal_with_syntax_off()
+ new
+
+ " To test targets in the same line string is replaced with conceal char
+ " correctly, repeat 'TARGET'
+ 1put ='TARGET_TARGETTARGET'
+ call cursor(1, 1)
+ redraw
+ call assert_equal('TARGET_TARGETTARGET', s:screenline(2))
+
+ setlocal conceallevel=2
+ call matchadd('Conceal', 'TARGET', 10, -1, {'conceal': 't'})
+
+ redraw
+ call assert_equal('t_tt', s:screenline(2))
+
+ quit!
+endfunction
diff --git a/src/nvim/testdir/test_matchadd_conceal_utf8.vim b/src/nvim/testdir/test_matchadd_conceal_utf8.vim
new file mode 100644
index 0000000000..24c848a99c
--- /dev/null
+++ b/src/nvim/testdir/test_matchadd_conceal_utf8.vim
@@ -0,0 +1,39 @@
+" Test for matchadd() and conceal feature using utf-8.
+if !has('conceal') || !has('multi_byte')
+ finish
+endif
+
+function! s:screenline(lnum) abort
+ let line = []
+ for c in range(1, winwidth(0))
+ call add(line, nr2char(screenchar(a:lnum, c)))
+ endfor
+ return s:trim(join(line, ''))
+endfunction
+
+function! s:trim(str) abort
+ return matchstr(a:str,'^\s*\zs.\{-}\ze\s*$')
+endfunction
+
+function! Test_match_using_multibyte_conceal_char()
+ new
+ setlocal concealcursor=n conceallevel=1
+
+ 1put='# This is a Test'
+ " 1234567890123456
+ let expect = '#ˑThisˑisˑaˑTest'
+
+ call cursor(1, 1)
+ call matchadd('Conceal', '\%2l ', 20, -1, {'conceal': "\u02d1"})
+ redraw!
+
+ let lnum = 2
+ call assert_equal(expect, s: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))
+
+ quit!
+endfunction
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 63acd22514..2efa81af1d 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -703,7 +703,7 @@ static int included_patches[] = {
// 1743 NA
// 1742,
// 1741,
- // 1740,
+ 1740,
// 1739,
// 1738,
// 1737 NA