aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Ennen <mike.ennen@gmail.com>2016-12-06 17:12:08 -0700
committerMichael Ennen <mike.ennen@gmail.com>2016-12-06 17:12:08 -0700
commit0064e9738aec725b9cf4b29f425b0da7ecc8fd46 (patch)
treed0b8cb81b4cd1b573abb301f99a9c626127b6cba
parent629e788b3689698f8cd96a71b0d5421d7456e770 (diff)
downloadrneovim-0064e9738aec725b9cf4b29f425b0da7ecc8fd46.tar.gz
rneovim-0064e9738aec725b9cf4b29f425b0da7ecc8fd46.tar.bz2
rneovim-0064e9738aec725b9cf4b29f425b0da7ecc8fd46.zip
vim-patch:7.4.2217
Problem: When using matchaddpos() a character after the end of the line can be highlighted. Solution: Only highlight existing characters. (Hirohito Higashi) https://github.com/vim/vim/commit/4f416e41243ca151b95d39d81ce23d00b1484755
-rw-r--r--src/nvim/buffer_defs.h5
-rw-r--r--src/nvim/screen.c29
-rw-r--r--src/nvim/testdir/test_match.vim26
-rw-r--r--src/nvim/version.c2
4 files changed, 46 insertions, 16 deletions
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index 4f0de1451a..65ce07a172 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -885,8 +885,9 @@ typedef struct {
int attr_cur; /* attributes currently active in win_line() */
linenr_T first_lnum; /* first lnum to search for multi-line pat */
colnr_T startcol; /* in win_line() points to char where HL starts */
- colnr_T endcol; /* in win_line() points to char where HL ends */
- proftime_T tm; /* for a time limit */
+ colnr_T endcol; // in win_line() points to char where HL ends
+ bool is_addpos; // position specified directly by matchaddpos()
+ proftime_T tm; // for a time limit
} match_T;
/// number of positions supported by matchaddpos()
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 9075f94a20..c5fe5e8b05 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -2592,6 +2592,7 @@ win_line (
shl->startcol = MAXCOL;
shl->endcol = MAXCOL;
shl->attr_cur = 0;
+ shl->is_addpos = false;
v = (long)(ptr - line);
if (cur != NULL) {
cur->pos.cur = 0;
@@ -3760,18 +3761,18 @@ win_line (
if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol)
++prevcol;
- /* Invert at least one char, used for Visual and empty line or
- * highlight match at end of line. If it's beyond the last
- * char on the screen, just overwrite that one (tricky!) Not
- * needed when a '$' was displayed for 'list'. */
- prevcol_hl_flag = FALSE;
- if (prevcol == (long)search_hl.startcol)
- prevcol_hl_flag = TRUE;
- else {
+ // Invert at least one char, used for Visual and empty line or
+ // highlight match at end of line. If it's beyond the last
+ // char on the screen, just overwrite that one (tricky!) Not
+ // needed when a '$' was displayed for 'list'.
+ prevcol_hl_flag = false;
+ if (!search_hl.is_addpos && prevcol == (long)search_hl.startcol) {
+ prevcol_hl_flag = true;
+ } else {
cur = wp->w_match_head;
while (cur != NULL) {
- if (prevcol == (long)cur->hl.startcol) {
- prevcol_hl_flag = TRUE;
+ if (!cur->hl.is_addpos && prevcol == (long)cur->hl.startcol) {
+ prevcol_hl_flag = true;
break;
}
cur = cur->next;
@@ -3821,10 +3822,13 @@ win_line (
shl_flag = TRUE;
} else
shl = &cur->hl;
- if ((ptr - line) - 1 == (long)shl->startcol)
+ if ((ptr - line) - 1 == (long)shl->startcol
+ && (shl == &search_hl || !shl->is_addpos)) {
char_attr = shl->attr;
- if (shl != &search_hl && cur != NULL)
+ }
+ if (shl != &search_hl && cur != NULL) {
cur = cur->next;
+ }
}
}
ScreenAttrs[off] = char_attr;
@@ -5737,6 +5741,7 @@ next_search_hl_pos(
shl->rm.startpos[0].col = start;
shl->rm.endpos[0].lnum = 0;
shl->rm.endpos[0].col = end;
+ shl->is_addpos = true;
posmatch->cur = bot + 1;
return true;
}
diff --git a/src/nvim/testdir/test_match.vim b/src/nvim/testdir/test_match.vim
index 57dde19bab..67f3ea7373 100644
--- a/src/nvim/testdir/test_match.vim
+++ b/src/nvim/testdir/test_match.vim
@@ -1,7 +1,7 @@
" Test for :match, :2match, :3match, clearmatches(), getmatches(), matchadd(),
" matchaddpos(), matcharg(), matchdelete(), matchstrpos() and setmatches().
-function Test_matcharg()
+function Test_match()
highlight MyGroup1 term=bold ctermbg=red guibg=red
highlight MyGroup2 term=italic ctermbg=green guibg=green
highlight MyGroup3 term=underline ctermbg=blue guibg=blue
@@ -162,4 +162,28 @@ func Test_matchstrpos()
call assert_equal(['', -1, -1, -1], matchstrpos(['vim', 'testing', 'execute'], 'img'))
endfunc
+func Test_matchaddpos()
+ syntax on
+ set hlsearch
+
+ call setline(1, ['12345', 'NP'])
+ call matchaddpos('Error', [[1,2], [1,6], [2,2]])
+ redraw!
+ call assert_notequal(screenattr(2,2), 0)
+ call assert_equal(screenattr(2,2), screenattr(1,2))
+ call assert_notequal(screenattr(2,2), screenattr(1,6))
+ 1
+ call matchadd('Search', 'N\|\n')
+ redraw!
+ call assert_notequal(screenattr(2,1), 0)
+ call assert_equal(screenattr(2,1), screenattr(1,6))
+ exec "norm! i0\<Esc>"
+ redraw!
+ call assert_equal(screenattr(2,2), screenattr(1,6))
+
+ nohl
+ syntax off
+ set hlsearch&
+endfunc
+
" vim: et ts=2 sw=2
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 0f97ad3262..a314817399 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -225,7 +225,7 @@ static int included_patches[] = {
// 2220,
2219,
// 2218 NA
- // 2217,
+ 2217,
// 2216 NA
// 2215,
// 2214 NA