aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-09-12 19:26:56 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-09-13 08:25:20 -0400
commit4327fe8da54ad090e3ca08473ff198ad7cc1f448 (patch)
tree9cad774daae773cca63260111fd17f097b6d51c0 /src
parentce325457083e8fac376028887a80e47e1f6e7d09 (diff)
downloadrneovim-4327fe8da54ad090e3ca08473ff198ad7cc1f448.tar.gz
rneovim-4327fe8da54ad090e3ca08473ff198ad7cc1f448.tar.bz2
rneovim-4327fe8da54ad090e3ca08473ff198ad7cc1f448.zip
vim-patch:8.2.0902: using searchcount() in 'statusline' causes an error
Problem: Using searchcount() in 'statusline' causes an error. Solution: Avoid saving/restoring the search patten recursively. (closes vim/vim#6194) https://github.com/vim/vim/commit/442a85369f3eb9834dbab42add45f7c4106700f4
Diffstat (limited to 'src')
-rw-r--r--src/nvim/search.c17
-rw-r--r--src/nvim/testdir/test_search_stat.vim30
2 files changed, 40 insertions, 7 deletions
diff --git a/src/nvim/search.c b/src/nvim/search.c
index d7984d675d..517db05a40 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -320,10 +320,9 @@ static bool saved_no_hlsearch = false;
/// cancelling incremental searching even if it's called inside user functions.
void save_last_search_pattern(void)
{
- if (did_save_last_search_spat != 0) {
- IEMSG("did_save_last_search_spat is not zero");
- } else {
- did_save_last_search_spat++;
+ if (++did_save_last_search_spat != 1) {
+ // nested call, nothing to do
+ return;
}
saved_last_search_spat = spats[RE_SEARCH];
@@ -336,11 +335,15 @@ void save_last_search_pattern(void)
void restore_last_search_pattern(void)
{
- if (did_save_last_search_spat != 1) {
- IEMSG("did_save_last_search_spat is not one");
+ if (--did_save_last_search_spat > 0) {
+ // nested call, nothing to do
+ return;
+ }
+ if (did_save_last_search_spat != 0) {
+ iemsg("restore_last_search_pattern() called more often than"
+ " save_last_search_pattern()");
return;
}
- did_save_last_search_spat--;
xfree(spats[RE_SEARCH].pat);
spats[RE_SEARCH] = saved_last_search_spat;
diff --git a/src/nvim/testdir/test_search_stat.vim b/src/nvim/testdir/test_search_stat.vim
index cf36f3214a..fa620b4e00 100644
--- a/src/nvim/testdir/test_search_stat.vim
+++ b/src/nvim/testdir/test_search_stat.vim
@@ -4,6 +4,8 @@
" as test!
source shared.vim
+source screendump.vim
+source check.vim
func! Test_search_stat()
new
@@ -164,3 +166,31 @@ func! Test_search_stat()
set shortmess+=S
bwipe!
endfunc
+
+func Test_searchcount_in_statusline()
+ CheckScreendump
+
+ let lines =<< trim END
+ set shortmess-=S
+ call append(0, 'this is something')
+ function TestSearchCount() abort
+ let search_count = searchcount()
+ if !empty(search_count)
+ return '[' . search_count.current . '/' . search_count.total . ']'
+ else
+ return ''
+ endif
+ endfunction
+ set hlsearch
+ set laststatus=2 statusline+=%{TestSearchCount()}
+ END
+ call writefile(lines, 'Xsearchstatusline')
+ let buf = RunVimInTerminal('-S Xsearchstatusline', #{rows: 10})
+ call TermWait(buf)
+ call term_sendkeys(buf, "/something")
+ call VerifyScreenDump(buf, 'Test_searchstat_4', {})
+
+ call term_sendkeys(buf, "\<Esc>")
+ call StopVimInTerminal(buf)
+ call delete('Xsearchstatusline')
+endfunc