diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/match.c | 20 | ||||
-rw-r--r-- | src/nvim/testdir/test_search.vim | 76 |
2 files changed, 64 insertions, 32 deletions
diff --git a/src/nvim/match.c b/src/nvim/match.c index cd8c65cc02..f41eab889b 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -738,7 +738,13 @@ int update_search_hl(win_T *wp, linenr_T lnum, colnr_T col, char_u **line, match if (shl->startcol == shl->endcol) { // highlight empty match, try again after it - shl->endcol += utfc_ptr2len((char *)(*line) + shl->endcol); + char *p = (char *)(*line) + shl->endcol; + + if (*p == NUL) { + shl->endcol++; + } else { + shl->endcol += utfc_ptr2len(p); + } } // Loop to check if the match starts at the @@ -792,12 +798,19 @@ bool get_prevcol_hl_flag(win_T *wp, match_T *search_hl, long curcol) prevcol++; } - if (!search_hl->is_addpos && prevcol == search_hl->startcol) { + // Highlight a character after the end of the line if the match started + // at the end of the line or when the match continues in the next line + // (match includes the line break). + if (!search_hl->is_addpos && (prevcol == (long)search_hl->startcol + || (prevcol > (long)search_hl->startcol + && search_hl->endcol == MAXCOL))) { return true; } else { cur = wp->w_match_head; while (cur != NULL) { - if (!cur->hl.is_addpos && prevcol == cur->hl.startcol) { + if (!cur->hl.is_addpos && (prevcol == (long)cur->hl.startcol + || (prevcol > (long)cur->hl.startcol + && cur->hl.endcol == MAXCOL))) { return true; } cur = cur->next; @@ -815,7 +828,6 @@ void get_search_match_hl(win_T *wp, match_T *search_hl, long col, int *char_attr bool shl_flag = false; // flag to indicate whether search_hl // has been processed or not - *char_attr = search_hl->attr; while (cur != NULL || !shl_flag) { if (!shl_flag && (cur == NULL || cur->priority > SEARCH_HL_PRIORITY)) { diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 3d1bbfb726..0cf55c7d0b 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -956,24 +956,24 @@ func Test_incsearch_search_dump() call delete('Xis_search_script') endfunc -func Test_hlsearch_block_visual_match() +func Test_hlsearch_dump() + CheckOption hlsearch CheckScreendump - let lines =<< trim END - set hlsearch - call setline(1, ['aa', 'bbbb', 'cccccc']) - END - call writefile(lines, 'Xhlsearch_block') - let buf = RunVimInTerminal('-S Xhlsearch_block', {'rows': 9, 'cols': 60}) + call writefile([ + \ 'set hlsearch cursorline', + \ 'call setline(1, ["xxx", "xxx", "xxx"])', + \ '/.*', + \ '2', + \ ], 'Xhlsearch_script') + let buf = RunVimInTerminal('-S Xhlsearch_script', {'rows': 6, 'cols': 50}) + call VerifyScreenDump(buf, 'Test_hlsearch_1', {}) - call term_sendkeys(buf, "G\<C-V>$kk\<Esc>") - sleep 100m - call term_sendkeys(buf, "/\\%V\<CR>") - sleep 100m - call VerifyScreenDump(buf, 'Test_hlsearch_block_visual_match', {}) + call term_sendkeys(buf, "/\\_.*\<CR>") + call VerifyScreenDump(buf, 'Test_hlsearch_2', {}) call StopVimInTerminal(buf) - call delete('Xhlsearch_block') + call delete('Xhlsearch_script') endfunc func Test_hlsearch_and_visual() @@ -996,6 +996,26 @@ func Test_hlsearch_and_visual() call delete('Xhlvisual_script') endfunc +func Test_hlsearch_block_visual_match() + CheckScreendump + + let lines =<< trim END + set hlsearch + call setline(1, ['aa', 'bbbb', 'cccccc']) + END + call writefile(lines, 'Xhlsearch_block') + let buf = RunVimInTerminal('-S Xhlsearch_block', {'rows': 9, 'cols': 60}) + + call term_sendkeys(buf, "G\<C-V>$kk\<Esc>") + sleep 100m + call term_sendkeys(buf, "/\\%V\<CR>") + sleep 100m + call VerifyScreenDump(buf, 'Test_hlsearch_block_visual_match', {}) + + call StopVimInTerminal(buf) + call delete('Xhlsearch_block') +endfunc + func Test_incsearch_substitute() CheckFunction test_override CheckOption incsearch @@ -1017,6 +1037,21 @@ func Test_incsearch_substitute() call Incsearch_cleanup() endfunc +func Test_incsearch_substitute_long_line() + CheckFunction test_override + new + call test_override("char_avail", 1) + set incsearch + + call repeat('x', 100000)->setline(1) + call feedkeys(':s/\%c', 'xt') + redraw + call feedkeys("\<Esc>", 'xt') + + call Incsearch_cleanup() + bwipe! +endfunc + func Test_hlsearch_cursearch() CheckScreendump @@ -1341,21 +1376,6 @@ func Test_subst_word_under_cursor() set noincsearch endfunc -func Test_incsearch_substitute_long_line() - CheckFunction test_override - new - call test_override("char_avail", 1) - set incsearch - - call repeat('x', 100000)->setline(1) - call feedkeys(':s/\%c', 'xt') - redraw - call feedkeys("\<Esc>", 'xt') - - call Incsearch_cleanup() - bwipe! -endfunc - func Test_search_undefined_behaviour() CheckFeature terminal |