summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-09-13 13:45:26 +0100
committerBram Moolenaar <Bram@vim.org>2022-09-13 13:45:26 +0100
commita04f457a6c071179bac4088c9314007d39d5c5e0 (patch)
treecd40106e2bff68c4f02b18b83f2dffb616d2ccb5
parentb1842de5ca77205993e8ef76cf29803822e0e3ab (diff)
downloadvim-git-a04f457a6c071179bac4088c9314007d39d5c5e0.tar.gz
patch 9.0.0457: substitute prompt does not highlight an empty matchv9.0.0457
Problem: Substitute prompt does not highlight an empty match. Solution: Highlight at least one character.
-rw-r--r--src/ex_cmds.c4
-rw-r--r--src/testdir/dumps/Test_sub_highlight_zer_match_1.dump8
-rw-r--r--src/testdir/test_substitute.vim16
-rw-r--r--src/version.c2
4 files changed, 30 insertions, 0 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 311b9b7c2..4938c6f48 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -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
index 000000000..481d0bb4e
--- /dev/null
+++ b/src/testdir/dumps/Test_sub_highlight_zer_match_1.dump
@@ -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|
diff --git a/src/testdir/test_substitute.vim b/src/testdir/test_substitute.vim
index df01e06f3..92e86a9a1 100644
--- a/src/testdir/test_substitute.vim
+++ b/src/testdir/test_substitute.vim
@@ -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()
diff --git a/src/version.c b/src/version.c
index 85e5a9d3b..019abf354 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 457,
+/**/
456,
/**/
455,