mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
vim-patch:9.0.1518: search stats not always visible when searching backwards (#23517)
Problem: Search stats not always visible when searching backwards.
Solution: Do not display the top/bot message on top of the search stats.
(Christian Brabandt, closes vim/vim#12322, closes vim/vim#12222)
34a6a3617b
Co-authored-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
parent
e218965338
commit
9e34aa76c1
@ -259,7 +259,7 @@ enum {
|
||||
SHM_COMPLETIONSCAN = 'C', ///< Completion scanning messages.
|
||||
SHM_RECORDING = 'q', ///< Short recording message.
|
||||
SHM_FILEINFO = 'F', ///< No file info messages.
|
||||
SHM_SEARCHCOUNT = 'S', ///< Search stats: '[1/10]'
|
||||
SHM_SEARCHCOUNT = 'S', ///< No search stats: '[1/10]'
|
||||
SHM_LEN = 30, ///< Max length of all flags together plus a NUL character.
|
||||
};
|
||||
/// Represented by 'a' flag.
|
||||
|
@ -913,19 +913,22 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir,
|
||||
|| found || loop) {
|
||||
break;
|
||||
}
|
||||
//
|
||||
|
||||
// If 'wrapscan' is set we continue at the other end of the file.
|
||||
// If 'shortmess' does not contain 's', we give a message.
|
||||
// If 'shortmess' does not contain 's', we give a message, but
|
||||
// only, if we won't show the search stat later anyhow,
|
||||
// (so SEARCH_COUNT must be absent).
|
||||
// This message is also remembered in keep_msg for when the screen
|
||||
// is redrawn. The keep_msg is cleared whenever another message is
|
||||
// written.
|
||||
//
|
||||
if (dir == BACKWARD) { // start second loop at the other end
|
||||
lnum = buf->b_ml.ml_line_count;
|
||||
} else {
|
||||
lnum = 1;
|
||||
}
|
||||
if (!shortmess(SHM_SEARCH) && (options & SEARCH_MSG)) {
|
||||
if (!shortmess(SHM_SEARCH)
|
||||
&& shortmess(SHM_SEARCHCOUNT)
|
||||
&& (options & SEARCH_MSG)) {
|
||||
give_warning(_(dir == BACKWARD ? top_bot_msg : bot_top_msg), true);
|
||||
}
|
||||
if (extra_arg != NULL) {
|
||||
@ -2702,8 +2705,10 @@ static void update_search_stat(int dirc, pos_T *pos, pos_T *cursor_pos, searchst
|
||||
lbuf = curbuf;
|
||||
}
|
||||
|
||||
// when searching backwards and having jumped to the first occurrence,
|
||||
// cur must remain greater than 1
|
||||
if (equalpos(lastpos, *cursor_pos) && !wraparound
|
||||
&& (dirc == 0 || dirc == '/' ? cur < cnt : cur > 0)) {
|
||||
&& (dirc == 0 || dirc == '/' ? cur < cnt : cur > 1)) {
|
||||
cur += dirc == 0 ? 0 : dirc == '/' ? 1 : -1;
|
||||
} else {
|
||||
proftime_T start;
|
||||
|
@ -10,8 +10,9 @@ describe('search stat', function()
|
||||
screen:set_default_attr_ids({
|
||||
[1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
|
||||
[2] = {background = Screen.colors.Yellow}, -- Search
|
||||
[3] = {foreground = Screen.colors.Blue4, background = Screen.colors.LightGrey}, -- Folded
|
||||
[3] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey}, -- Folded
|
||||
[4] = {reverse = true}, -- IncSearch, TabLineFill
|
||||
[5] = {foreground = Screen.colors.Red}, -- WarningMsg
|
||||
})
|
||||
screen:attach()
|
||||
end)
|
||||
@ -183,4 +184,57 @@ describe('search stat', function()
|
||||
/abc^ |
|
||||
]])
|
||||
end)
|
||||
|
||||
-- oldtest: Test_search_stat_backwards()
|
||||
it('when searching backwards', function()
|
||||
screen:try_resize(60, 10)
|
||||
exec([[
|
||||
set shm-=S
|
||||
call setline(1, ['test', ''])
|
||||
]])
|
||||
|
||||
feed('*')
|
||||
screen:expect([[
|
||||
{2:^test} |
|
||||
|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
/\<test\> [1/1] |
|
||||
]])
|
||||
|
||||
feed('N')
|
||||
screen:expect([[
|
||||
{2:^test} |
|
||||
|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
?\<test\> [1/1] |
|
||||
]])
|
||||
|
||||
command('set shm+=S')
|
||||
feed('N')
|
||||
-- shows "Search Hit Bottom.."
|
||||
screen:expect([[
|
||||
{2:^test} |
|
||||
|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{5:search hit TOP, continuing at BOTTOM} |
|
||||
]])
|
||||
end)
|
||||
end)
|
||||
|
@ -153,7 +153,6 @@ func Test_search_stat()
|
||||
let g:a = execute(':unsilent :norm! n')
|
||||
let stat = 'W \[20/1\]'
|
||||
call assert_match(pat .. stat, g:a)
|
||||
call assert_match('search hit BOTTOM, continuing at TOP', g:a)
|
||||
set norl
|
||||
endif
|
||||
|
||||
@ -164,7 +163,6 @@ func Test_search_stat()
|
||||
let g:a = execute(':unsilent :norm! N')
|
||||
let stat = 'W \[20/20\]'
|
||||
call assert_match(pat .. stat, g:a)
|
||||
call assert_match('search hit TOP, continuing at BOTTOM', g:a)
|
||||
call assert_match('W \[20/20\]', Screenline(&lines))
|
||||
|
||||
" normal, no match
|
||||
@ -422,7 +420,7 @@ func Test_search_stat_and_incsearch()
|
||||
|
||||
set tabline=%!MyTabLine()
|
||||
END
|
||||
call writefile(lines, 'Xsearchstat_inc')
|
||||
call writefile(lines, 'Xsearchstat_inc', 'D')
|
||||
|
||||
let buf = RunVimInTerminal('-S Xsearchstat_inc', #{rows: 10})
|
||||
call term_sendkeys(buf, "/abc")
|
||||
@ -441,8 +439,35 @@ func Test_search_stat_and_incsearch()
|
||||
call TermWait(buf)
|
||||
|
||||
call StopVimInTerminal(buf)
|
||||
call delete('Xsearchstat_inc')
|
||||
endfunc
|
||||
|
||||
func Test_search_stat_backwards()
|
||||
CheckScreendump
|
||||
|
||||
let lines =<< trim END
|
||||
set shm-=S
|
||||
call setline(1, ['test', ''])
|
||||
END
|
||||
call writefile(lines, 'Xsearchstat_back', 'D')
|
||||
|
||||
let buf = RunVimInTerminal('-S Xsearchstat_back', #{rows: 10})
|
||||
call term_sendkeys(buf, "*")
|
||||
call TermWait(buf)
|
||||
call VerifyScreenDump(buf, 'Test_searchstat_back_1', {})
|
||||
|
||||
call term_sendkeys(buf, "N")
|
||||
call TermWait(buf)
|
||||
call VerifyScreenDump(buf, 'Test_searchstat_back_2', {})
|
||||
|
||||
call term_sendkeys(buf, ":set shm+=S\<cr>N")
|
||||
call TermWait(buf)
|
||||
" shows "Search Hit Bottom.."
|
||||
call VerifyScreenDump(buf, 'Test_searchstat_back_3', {})
|
||||
|
||||
call term_sendkeys(buf, "\<esc>:qa\<cr>")
|
||||
call TermWait(buf)
|
||||
|
||||
call StopVimInTerminal(buf)
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
Loading…
Reference in New Issue
Block a user