]> granicus.if.org Git - vim/commitdiff
patch 9.0.0457: substitute prompt does not highlight an empty match v9.0.0457
authorBram Moolenaar <Bram@vim.org>
Tue, 13 Sep 2022 12:45:26 +0000 (13:45 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 13 Sep 2022 12:45:26 +0000 (13:45 +0100)
Problem:    Substitute prompt does not highlight an empty match.
Solution:   Highlight at least one character.

src/ex_cmds.c
src/testdir/dumps/Test_sub_highlight_zer_match_1.dump [new file with mode: 0644]
src/testdir/test_substitute.vim
src/version.c

index 311b9b7c2f1f0ff677528c2b384883f22a6ea383..4938c6f485d79d11ade9c8df0ea29a9aa406298a 100644 (file)
@@ -4308,6 +4308,10 @@ ex_substitute(exarg_T *eap)
                                                  - regmatch.startpos[0].lnum;
                            search_match_endcol = regmatch.endpos[0].col
                                                                 + len_change;
+                           if (search_match_lines == 0
+                                                  && search_match_endcol == 0)
+                               // highlight at least one character for /^/
+                               search_match_endcol = 1;
                            highlight_match = TRUE;
 
                            update_topline();
diff --git a/src/testdir/dumps/Test_sub_highlight_zer_match_1.dump b/src/testdir/dumps/Test_sub_highlight_zer_match_1.dump
new file mode 100644 (file)
index 0000000..481d0bb
--- /dev/null
@@ -0,0 +1,8 @@
+|o+1&#ffffff0|n+0&&|e| @56
+|t|w|o| @56
+|t|h|r|e@1| @54
+|~+0#4040ff13&| @58
+|~| @58
+|~| @58
+|~| @58
+|r+0#00e0003&|e|p|l|a|c|e| |w|i|t|h| @1|.@2|/|a|/|q|/|l|/|^|E|/|^|Y|)|?> +0#0000000&@10|1|,|1| @10|A|l@1| 
index df01e06f3ac5ddc4fb0a8ca0bdafb8c295fd8bf3..92e86a9a1035a23019aae46dd8e0cdb2dc5cab95 100644 (file)
@@ -2,6 +2,7 @@
 
 source shared.vim
 source check.vim
+source screendump.vim
 
 func Test_multiline_subst()
   enew!
@@ -684,6 +685,21 @@ func Test_sub_cmd_9()
   bw!
 endfunc
 
+func Test_sub_highlight_zero_match()
+  CheckRunVimInTerminal
+
+  let lines =<< trim END
+    call setline(1, ['one', 'two', 'three'])
+  END
+  call writefile(lines, 'XscriptSubHighlight', 'D')
+  let buf = RunVimInTerminal('-S XscriptSubHighlight', #{rows: 8, cols: 60})
+  call term_sendkeys(buf, ":%s/^/   /c\<CR>")
+  call VerifyScreenDump(buf, 'Test_sub_highlight_zer_match_1', {})
+
+  call term_sendkeys(buf, "\<Esc>")
+  call StopVimInTerminal(buf)
+endfunc
+
 func Test_nocatch_sub_failure_handling()
   " normal error results in all replacements 
   func Foo()
index 85e5a9d3b17130aec56eb057352cda9ba1fce87d..019abf35486dafc2dcf32d1ba0c46e2e208780e4 100644 (file)
@@ -703,6 +703,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    457,
 /**/
     456,
 /**/