]> granicus.if.org Git - vim/commitdiff
patch 9.0.1298: inserting register on the cmdline does not trigger incsearch v9.0.1298
authorK.Takata <kentkt@csc.jp>
Fri, 10 Feb 2023 21:38:44 +0000 (21:38 +0000)
committerBram Moolenaar <Bram@vim.org>
Fri, 10 Feb 2023 21:38:44 +0000 (21:38 +0000)
Problem:    Inserting a register on the command line does not trigger
            incsearch or update hlsearch.
Solution:   Have cmdline_insert_reg() return CMDLINE_CHANGED when appropriate
            and handle it correctly. (Ken Takata, closes #11960)

src/ex_getln.c
src/testdir/dumps/Test_hlsearch_ctrlr_1.dump [new file with mode: 0644]
src/testdir/test_hlsearch.vim
src/version.c

index 6d0b3c5db62724a6d9a82fc6d95cc232a5006524..d40f923382c3a9a77868feee4ecbc77eac2ce29b 100644 (file)
@@ -1183,6 +1183,7 @@ cmdline_insert_reg(int *gotesc UNUSED)
 {
     int                i;
     int                c;
+    int                literally = FALSE;
 #ifdef FEAT_EVAL
     int                save_new_cmdpos = new_cmdpos;
 #endif
@@ -1220,7 +1221,8 @@ cmdline_insert_reg(int *gotesc UNUSED)
 #endif
     if (c != ESC)          // use ESC to cancel inserting register
     {
-       cmdline_paste(c, i == Ctrl_R, FALSE);
+       literally = i == Ctrl_R;
+       cmdline_paste(c, literally, FALSE);
 
 #ifdef FEAT_EVAL
        // When there was a serious error abort getting the
@@ -1251,8 +1253,9 @@ cmdline_insert_reg(int *gotesc UNUSED)
     // remove the double quote
     redrawcmd();
 
-    // The text has been stuffed, the command line didn't change yet.
-    return CMDLINE_NOT_CHANGED;
+    // The text has been stuffed, the command line didn't change yet, but it
+    // will change soon.  The caller must take care of it.
+    return literally ? CMDLINE_NOT_CHANGED : CMDLINE_CHANGED;
 }
 
 /*
@@ -2081,11 +2084,13 @@ getcmdline_int(
 
        case Ctrl_R:                    // insert register
                res = cmdline_insert_reg(&gotesc);
-               if (res == CMDLINE_NOT_CHANGED)
-                   goto cmdline_not_changed;
-               else if (res == GOTO_NORMAL_MODE)
+               if (res == GOTO_NORMAL_MODE)
                    goto returncmd;
-               goto cmdline_changed;
+#ifdef FEAT_SEARCH_EXTRA
+               if (res == CMDLINE_NOT_CHANGED)
+                   is_state.incsearch_postponed = TRUE;
+#endif
+               goto cmdline_not_changed;
 
        case Ctrl_D:
                if (showmatches(&xpc, FALSE) == EXPAND_NOTHING)
diff --git a/src/testdir/dumps/Test_hlsearch_ctrlr_1.dump b/src/testdir/dumps/Test_hlsearch_ctrlr_1.dump
new file mode 100644 (file)
index 0000000..e0a0af3
--- /dev/null
@@ -0,0 +1,6 @@
+| +0&#ffffff0@59
+|t+1&&|e|x|t| +0&&@55
+|~+0#4040ff13&| @58
+|~| @58
+|~| @58
+|/+0#0000000&|t|e|x|t> @54
index 4227dbd6d51be7704de550b32d7a002c0a327078..476c075a5d0fc4e7ff205a99caf3bdbcde3ec713 100644 (file)
@@ -1,6 +1,7 @@
 " Test for v:hlsearch
 
 source check.vim
+source screendump.vim
 
 func Test_hlsearch()
   new
@@ -72,4 +73,22 @@ func Test_hlsearch_eol_highlight()
   bwipe!
 endfunc
 
+func Test_hlsearch_Ctrl_R()
+  CheckRunVimInTerminal
+
+  let lines =<< trim END
+      set incsearch hlsearch
+      let @" = "text"
+      put
+  END
+  call writefile(lines, 'XhlsearchCtrlR', 'D')
+  let buf = RunVimInTerminal('-S XhlsearchCtrlR', #{rows: 6, cols: 60})
+
+  call term_sendkeys(buf, "/\<C-R>\<C-R>\"")
+  call VerifyScreenDump(buf, 'Test_hlsearch_ctrlr_1', {})
+
+  call term_sendkeys(buf, "\<Esc>")
+  call StopVimInTerminal(buf)
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 26b4048210130bd8fcf6897e8b328ccb28b4423c..f50677b4052586fcf1e0de46e791d3b24ddafd36 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1298,
 /**/
     1297,
 /**/