mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
vim-patch:8.2.4805: CurSearch used for all matches in current line
Problem: CurSearch used for all matches in current line.
Solution: Don't use the non-zero line count. (closes vim/vim#10247)
9b36750640
This commit is contained in:
parent
4e4914ab2e
commit
8db55aedb5
@ -560,6 +560,22 @@ void prepare_search_hl(win_T *wp, match_T *search_hl, linenr_T lnum)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update "shl->has_cursor" based on the match in "shl" and the cursor
|
||||||
|
/// position.
|
||||||
|
static void check_cur_search_hl(win_T *wp, match_T *shl)
|
||||||
|
{
|
||||||
|
long linecount = shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum;
|
||||||
|
|
||||||
|
if (wp->w_cursor.lnum >= shl->lnum
|
||||||
|
&& wp->w_cursor.lnum <= shl->lnum + shl->rm.endpos[0].lnum
|
||||||
|
&& (wp->w_cursor.lnum > shl->lnum || wp->w_cursor.col >= shl->rm.startpos[0].col)
|
||||||
|
&& (wp->w_cursor.lnum < shl->lnum + linecount || wp->w_cursor.col < shl->rm.endpos[0].col)) {
|
||||||
|
shl->has_cursor = true;
|
||||||
|
} else {
|
||||||
|
shl->has_cursor = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Prepare for 'hlsearch' and match highlighting in one window line.
|
/// Prepare for 'hlsearch' and match highlighting in one window line.
|
||||||
/// Return true if there is such highlighting and set "search_attr" to the
|
/// Return true if there is such highlighting and set "search_attr" to the
|
||||||
/// current highlight attribute.
|
/// current highlight attribute.
|
||||||
@ -609,20 +625,14 @@ bool prepare_search_hl_line(win_T *wp, linenr_T lnum, colnr_T mincol, char_u **l
|
|||||||
} else {
|
} else {
|
||||||
shl->endcol = MAXCOL;
|
shl->endcol = MAXCOL;
|
||||||
}
|
}
|
||||||
if (shl->rm.endpos[0].lnum != shl->rm.startpos[0].lnum) {
|
shl->lines = shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum;
|
||||||
shl->lines = shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum;
|
if (shl->lines == 0) {
|
||||||
} else {
|
|
||||||
shl->lines = 1;
|
shl->lines = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the cursor is in the match before changing the columns
|
// check if the cursor is in the match before changing the columns
|
||||||
if (wp->w_cursor.lnum >= shl->lnum
|
if (shl == search_hl) {
|
||||||
&& wp->w_cursor.lnum <= shl->lnum + shl->rm.endpos[0].lnum
|
check_cur_search_hl(wp, shl);
|
||||||
&& (wp->w_cursor.lnum > shl->lnum
|
|
||||||
|| wp->w_cursor.col >= shl->rm.startpos[0].col)
|
|
||||||
&& (wp->w_cursor.lnum < shl->lnum + shl->lines
|
|
||||||
|| wp->w_cursor.col < shl->rm.endpos[0].col)) {
|
|
||||||
shl->has_cursor = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Highlight one character for an empty match.
|
// Highlight one character for an empty match.
|
||||||
@ -723,6 +733,11 @@ int update_search_hl(win_T *wp, linenr_T lnum, colnr_T col, char_u **line, match
|
|||||||
shl->endcol = MAXCOL;
|
shl->endcol = MAXCOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if the cursor is in the match
|
||||||
|
if (shl == search_hl) {
|
||||||
|
check_cur_search_hl(wp, shl);
|
||||||
|
}
|
||||||
|
|
||||||
if (shl->startcol == shl->endcol) {
|
if (shl->startcol == shl->endcol) {
|
||||||
// highlight empty match, try again after it
|
// highlight empty match, try again after it
|
||||||
shl->endcol += utfc_ptr2len(*line + shl->endcol);
|
shl->endcol += utfc_ptr2len(*line + shl->endcol);
|
||||||
|
@ -951,7 +951,7 @@ func Test_hlsearch_cursearch()
|
|||||||
|
|
||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
set hlsearch scrolloff=0
|
set hlsearch scrolloff=0
|
||||||
call setline(1, ['one', 'foo', 'bar', 'baz', 'foo', 'bar'])
|
call setline(1, ['one', 'foo', 'bar', 'baz', 'foo the foo and foo', 'bar'])
|
||||||
hi Search ctermbg=yellow
|
hi Search ctermbg=yellow
|
||||||
hi CurSearch ctermbg=blue
|
hi CurSearch ctermbg=blue
|
||||||
END
|
END
|
||||||
@ -964,7 +964,14 @@ func Test_hlsearch_cursearch()
|
|||||||
call term_sendkeys(buf, "n")
|
call term_sendkeys(buf, "n")
|
||||||
call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_2', {})
|
call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_2', {})
|
||||||
|
|
||||||
call term_sendkeys(buf, "?\<CR>")
|
call term_sendkeys(buf, "n")
|
||||||
|
call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_2a', {})
|
||||||
|
|
||||||
|
call term_sendkeys(buf, "n")
|
||||||
|
call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_2b', {})
|
||||||
|
|
||||||
|
call term_sendkeys(buf, ":call setline(5, 'foo')\<CR>")
|
||||||
|
call term_sendkeys(buf, "0?\<CR>")
|
||||||
call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_3', {})
|
call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_3', {})
|
||||||
|
|
||||||
call term_sendkeys(buf, "gg/foo\\nbar\<CR>")
|
call term_sendkeys(buf, "gg/foo\\nbar\<CR>")
|
||||||
|
@ -163,14 +163,14 @@ describe('search highlighting', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('works for multiline match', function()
|
it('works for multiline match', function()
|
||||||
command([[call setline(1, ['one', 'foo', 'bar', 'baz', 'foo', 'bar'])]])
|
command([[call setline(1, ['one', 'foo', 'bar', 'baz', 'foo the foo and foo', 'bar'])]])
|
||||||
feed('gg/foo<CR>')
|
feed('gg/foo<CR>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
one |
|
one |
|
||||||
{2:^foo} |
|
{2:^foo} |
|
||||||
bar |
|
bar |
|
||||||
baz |
|
baz |
|
||||||
{1:foo} |
|
{1:foo} the {1:foo} and {1:foo} |
|
||||||
bar |
|
bar |
|
||||||
/foo |
|
/foo |
|
||||||
]])
|
]])
|
||||||
@ -180,11 +180,32 @@ describe('search highlighting', function()
|
|||||||
{1:foo} |
|
{1:foo} |
|
||||||
bar |
|
bar |
|
||||||
baz |
|
baz |
|
||||||
{2:^foo} |
|
{2:^foo} the {1:foo} and {1:foo} |
|
||||||
bar |
|
bar |
|
||||||
/foo |
|
/foo |
|
||||||
]])
|
]])
|
||||||
feed('?<CR>')
|
feed('n')
|
||||||
|
screen:expect([[
|
||||||
|
one |
|
||||||
|
{1:foo} |
|
||||||
|
bar |
|
||||||
|
baz |
|
||||||
|
{1:foo} the {2:^foo} and {1:foo} |
|
||||||
|
bar |
|
||||||
|
/foo |
|
||||||
|
]])
|
||||||
|
feed('n')
|
||||||
|
screen:expect([[
|
||||||
|
one |
|
||||||
|
{1:foo} |
|
||||||
|
bar |
|
||||||
|
baz |
|
||||||
|
{1:foo} the {1:foo} and {2:^foo} |
|
||||||
|
bar |
|
||||||
|
/foo |
|
||||||
|
]])
|
||||||
|
command([[call setline(5, 'foo')]])
|
||||||
|
feed('0?<CR>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
one |
|
one |
|
||||||
{2:^foo} |
|
{2:^foo} |
|
||||||
|
Loading…
Reference in New Issue
Block a user