]> granicus.if.org Git - vim/commitdiff
patch 8.2.4378: incsearch HL broken when calling searchcount in 'tabLine' v8.2.4378
authorChristian Brabandt <cb@256bit.org>
Mon, 14 Feb 2022 12:44:32 +0000 (12:44 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 14 Feb 2022 12:44:32 +0000 (12:44 +0000)
Problem:    Incsearch highlight broken when calling searchcount() in 'tabLine'
            function. (Mirko Palmer)
Solution:   Save and restore the incsearch state. (Christian Brabandt,
            closes #9763, closes #9633)

src/search.c
src/testdir/dumps/Test_searchstat_inc_1.dump [new file with mode: 0644]
src/testdir/dumps/Test_searchstat_inc_2.dump [new file with mode: 0644]
src/testdir/dumps/Test_searchstat_inc_3.dump [new file with mode: 0644]
src/testdir/test_search_stat.vim
src/version.c

index 641d439a486e0339f2c40e027d0c65cd925a4038..f4c2c873b7e63b589d6962e033c4952b182689c9 100644 (file)
@@ -325,6 +325,8 @@ static spat_T           saved_last_search_spat;
 static int         did_save_last_search_spat = 0;
 static int         saved_last_idx = 0;
 static int         saved_no_hlsearch = 0;
+static int         saved_search_match_endcol;
+static int         saved_search_match_lines;
 
 /*
  * Save and restore the search pattern for incremental highlight search
@@ -370,6 +372,25 @@ restore_last_search_pattern(void)
     set_no_hlsearch(saved_no_hlsearch);
 }
 
+/*
+ * Save and restore the incsearch highlighting variables.
+ * This is required so that calling searchcount() at does not invalidate the
+ * incsearch highlighting.
+ */
+    static void
+save_incsearch_state(void)
+{
+    saved_search_match_endcol = search_match_endcol;
+    saved_search_match_lines  = search_match_lines;
+}
+
+    static void
+restore_incsearch_state(void)
+{
+    search_match_endcol = saved_search_match_endcol;
+    search_match_lines  = saved_search_match_lines;
+}
+
     char_u *
 last_search_pattern(void)
 {
@@ -4182,6 +4203,9 @@ f_searchcount(typval_T *argvars, typval_T *rettv)
     }
 
     save_last_search_pattern();
+#ifdef FEAT_SEARCH_EXTRA
+    save_incsearch_state();
+#endif
     if (pattern != NULL)
     {
        if (*pattern == NUL)
@@ -4202,6 +4226,9 @@ f_searchcount(typval_T *argvars, typval_T *rettv)
 
 the_end:
     restore_last_search_pattern();
+#ifdef FEAT_SEARCH_EXTRA
+    restore_incsearch_state();
+#endif
 }
 
 /*
diff --git a/src/testdir/dumps/Test_searchstat_inc_1.dump b/src/testdir/dumps/Test_searchstat_inc_1.dump
new file mode 100644 (file)
index 0000000..aa4b6c5
--- /dev/null
@@ -0,0 +1,10 @@
+| +1&#ffffff0@74
+|a+0#0000001#ffff4012|b|c|-+0#0000000#ffffff0@1|c| @68
+|-@7|a+1&&|b|c| +0&&@63
+|-@1|a+0#0000001#ffff4012|b|c| +0#0000000#ffffff0@69
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|/+0#0000000&|a|b|c> @70
diff --git a/src/testdir/dumps/Test_searchstat_inc_2.dump b/src/testdir/dumps/Test_searchstat_inc_2.dump
new file mode 100644 (file)
index 0000000..3b580ef
--- /dev/null
@@ -0,0 +1,10 @@
+|3+1&#ffffff0|/|3| @71
+|a+0#0000001#ffff4012|b|c|-+0#0000000#ffffff0@1|c| @68
+|-@7|a+0#0000001#ffff4012|b|c| +0#0000000#ffffff0@63
+|-@1|a+1&&|b|c| +0&&@69
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|/+0#0000000&|a|b|c> @70
diff --git a/src/testdir/dumps/Test_searchstat_inc_3.dump b/src/testdir/dumps/Test_searchstat_inc_3.dump
new file mode 100644 (file)
index 0000000..a57b4d1
--- /dev/null
@@ -0,0 +1,10 @@
+|1+1&#ffffff0|/|3| @71
+|a|b|c|-+0&&@1|c| @68
+|-@7|a+0#0000001#ffff4012|b|c| +0#0000000#ffffff0@63
+|-@1|a+0#0000001#ffff4012|b|c| +0#0000000#ffffff0@69
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|/+0#0000000&|a|b|c> @70
index 15da1555629381d8481dd875ef4ee199c531d192..e0820e42224161239c75f7fccffa2e43d146b099 100644 (file)
@@ -371,6 +371,48 @@ func Test_search_stat_then_gd()
   call delete('Xsearchstatgd')
 endfunc
 
+func Test_search_stat_and_incsearch()
+  CheckScreendump
+
+  let lines =<< trim END
+    call setline(1, ['abc--c', '--------abc', '--abc'])
+    set hlsearch
+    set incsearch
+    set bg=dark
+    set showtabline=2
+
+    function MyTabLine()
+    try
+      let a=searchcount(#{recompute: 1, maxcount: -1})
+      return a.current .. '/' .. a.total
+    catch
+      return ''
+    endtry
+    endfunction
+
+    set tabline=%!MyTabLine()
+  END
+  call writefile(lines, 'Xsearchstat_inc')
+
+  let buf = RunVimInTerminal('-S Xsearchstat_inc', #{rows: 10})
+  call term_sendkeys(buf, "/abc")
+  call TermWait(buf)
+  call VerifyScreenDump(buf, 'Test_searchstat_inc_1', {})
+
+  call term_sendkeys(buf, "\<c-g>")
+  call TermWait(buf)
+  call VerifyScreenDump(buf, 'Test_searchstat_inc_2', {})
+
+  call term_sendkeys(buf, "\<c-g>")
+  call TermWait(buf)
+  call VerifyScreenDump(buf, 'Test_searchstat_inc_3', {})
+
+  call term_sendkeys(buf, "\<esc>:qa\<cr>")
+  call TermWait(buf)
+
+  call StopVimInTerminal(buf)
+  call delete('Xsearchstat_inc')
+endfunc
 
 
 " vim: shiftwidth=2 sts=2 expandtab
index 17bc3f7c9b7e7bf5d6c9d7a0b8ffaf0d6fde27b6..4b2ac38bbc823515bf377545e371aafb30c47566 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4378,
 /**/
     4377,
 /**/