vim-patch:9.2.0838: searchcount() returns wrong cached maxcount (#40913)

Problem:  Cached searchcount() returns 'maxsearchcount' instead of the
          requested maxcount.
Solution: return the remembered last_maxcount (glepnir)

closes: vim/vim#20701

4352dc6ab0

Co-authored-by: glepnir <glephunter@gmail.com>
This commit is contained in:
zeertzjq
2026-07-23 09:03:29 +08:00
committed by GitHub
parent 05c5cf7e40
commit 53cbf66bd2
2 changed files with 14 additions and 1 deletions

View File

@@ -2740,7 +2740,7 @@ static void update_search_stat(int dirc, pos_T *pos, pos_T *cursor_pos, searchst
stat->cnt = cnt;
stat->exact_match = exact_match;
stat->incomplete = incomplete;
stat->last_maxcount = (int)p_msc;
stat->last_maxcount = last_maxcount;
return;
}
last_maxcount = maxcount;

View File

@@ -2363,4 +2363,17 @@ func Test_incsearch_delimiter_ctrlg()
call StopVimInTerminal(buf)
endfunc
func Test_searchcount_maxcount_cached()
new
call setline(1, repeat(['foo'], 5))
set maxsearchcount=99
let @/ = 'foo'
call cursor(1, 1)
call searchcount(#{recompute: v:true, maxcount: 3})
let r = searchcount(#{recompute: v:false, maxcount: 3})
call assert_equal(3, r.maxcount)
set maxsearchcount&
bwipe!
endfunc
" vim: shiftwidth=2 sts=2 expandtab