]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1555: setcharsearch() does not clear last searched char properly v9.0.1555
authorzeertzjq <zeertzjq@outlook.com>
Sun, 14 May 2023 16:39:18 +0000 (17:39 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 14 May 2023 16:39:18 +0000 (17:39 +0100)
Problem:    setcharsearch() does not clear last searched char properly.
Solution:   Do not accept lastc_bytelen smaller than one. (closes #12398)

src/search.c
src/testdir/test_charsearch.vim
src/testdir/test_charsearch_utf8.vim
src/version.c

index 793e042341d69ff3d9396197a8ed592e391c7b8f..de17595257aecd6d9729fcc8db34d58a9e18725a 100644 (file)
@@ -496,7 +496,7 @@ last_csearch_until(void)
 }
 
     void
-set_last_csearch(int c, char_u *s UNUSED, int len UNUSED)
+set_last_csearch(int c, char_u *s, int len)
 {
     *lastc = c;
     lastc_bytelen = len;
@@ -1789,7 +1789,7 @@ searchc(cmdarg_T *cap, int t_cmd)
     }
     else               // repeat previous search
     {
-       if (*lastc == NUL && lastc_bytelen == 1)
+       if (*lastc == NUL && lastc_bytelen <= 1)
            return FAIL;
        if (dir)        // repeat in opposite direction
            dir = -lastcdir;
@@ -1833,7 +1833,7 @@ searchc(cmdarg_T *cap, int t_cmd)
                        return FAIL;
                    col -= (*mb_head_off)(p, p + col - 1) + 1;
                }
-               if (lastc_bytelen == 1)
+               if (lastc_bytelen <= 1)
                {
                    if (p[col] == c && stop)
                        break;
index 142e6c8f2af66ce76fc098637eaa2e87a14edfe5..9b7c9a0a09ea16aaf068d7599e1f020b8ca98980 100644 (file)
@@ -38,6 +38,8 @@ func Test_charsearch()
   " clear the character search
   call setcharsearch({'char' : ''})
   call assert_equal('', getcharsearch().char)
+  call assert_beeps('normal ;')
+  call assert_beeps('normal ,')
 
   call assert_fails("call setcharsearch([])", 'E1206:')
   enew!
index 82a807ac5be7913feeb39556d8f32a2ef10b386d..843edbb5144cb5ac97692c70a36ffac426449abc 100644 (file)
@@ -13,6 +13,13 @@ func Test_search_cmds()
   call assert_equal([0, 1, 43, 0], getpos('.'))
   normal! ,
   call assert_equal([0, 1, 28, 0], getpos('.'))
+  call assert_equal('最', getcharsearch().char)
+  call setcharsearch({'char' : ''})
+  call assert_equal('', getcharsearch().char)
+  call assert_beeps('normal ;')
+  call assert_equal([0, 1, 28, 0], getpos('.'))
+  call assert_beeps('normal ,')
+  call assert_equal([0, 1, 28, 0], getpos('.'))
   bw!
 endfunc
 
index 8620f9732b07fcc13a5255e9d028db9b60a75874..292f2285f842e44afab329fa52d4f17803e2a40a 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1555,
 /**/
     1554,
 /**/