summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-03-27 13:36:50 +0100
committerBram Moolenaar <Bram@vim.org>2022-03-27 13:36:50 +0100
commitc75bca3ee955ff36ece99a42041733ddea5f45a7 (patch)
treef162d3638e42976309fde9f6631b082100e93546
parentf3980dc5d0a5f873cf764b8ba3e567e42259e4e5 (diff)
downloadvim-git-c75bca3ee955ff36ece99a42041733ddea5f45a7.tar.gz
patch 8.2.4633: Visual range does not work before command modifiersv8.2.4633
Problem: Visual range does not work before command modifiers. Solution: Move Visual range to after command modifiers.
-rw-r--r--src/ex_docmd.c30
-rw-r--r--src/testdir/test_source.vim7
-rw-r--r--src/version.c2
3 files changed, 35 insertions, 4 deletions
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 5e7cb8364..9b3504f76 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -2782,13 +2782,25 @@ parse_command_modifiers(
cmdmod_T *cmod,
int skip_only)
{
+ char_u *cmd_start;
char_u *p;
int starts_with_colon = FALSE;
int vim9script = in_vim9script();
+ int has_visual_range = FALSE;
CLEAR_POINTER(cmod);
cmod->cmod_flags = sticky_cmdmod_flags;
+ if (STRNCMP(eap->cmd, "'<,'>", 5) == 0)
+ {
+ // The automatically inserted Visual area range is skipped, so that
+ // typing ":cmdmod cmd" in Visual mode works without having to move the
+ // range to after the modififiers.
+ eap->cmd += 5;
+ cmd_start = eap->cmd;
+ has_visual_range = TRUE;
+ }
+
// Repeat until no more command modifiers are found.
for (;;)
{
@@ -2849,12 +2861,11 @@ parse_command_modifiers(
{
char_u *s, *n;
- for (s = p; ASCII_ISALPHA(*s); ++s)
+ for (s = eap->cmd; ASCII_ISALPHA(*s); ++s)
;
n = skipwhite(s);
- if (vim_strchr((char_u *)".=", *n) != NULL
- || *s == '['
- || (*n != NUL && n[1] == '='))
+ if (*n == '.' || *n == '=' || (*n != NUL && n[1] == '=')
+ || *s == '[')
break;
}
@@ -3081,6 +3092,17 @@ parse_command_modifiers(
break;
}
+ if (has_visual_range && eap->cmd > cmd_start)
+ {
+ // Move the '<,'> range to after the modifiers and insert a colon.
+ // Since the modifiers have been parsed put the colon on top of the
+ // space: "'<,'>mod cmd" -> "mod:'<,'>cmd
+ // Put eap->cmd after the colon.
+ mch_memmove(cmd_start - 5, cmd_start, eap->cmd - cmd_start);
+ eap->cmd -= 5;
+ mch_memmove(eap->cmd - 1, ":'<,'>", 6);
+ }
+
return OK;
}
diff --git a/src/testdir/test_source.vim b/src/testdir/test_source.vim
index 010401084..35d145374 100644
--- a/src/testdir/test_source.vim
+++ b/src/testdir/test_source.vim
@@ -579,6 +579,13 @@ func Test_source_buffer_vim9()
call assert_equal(#{pi: 3.12, e: 2.71828}, g:Math)
call assert_equal(['vim', 'nano'], g:Editors)
+ " '<,'> range before the cmd modifier works
+ unlet g:Math
+ unlet g:Editors
+ exe "normal 6GV4j:vim9cmd source\<CR>"
+ call assert_equal(['vim', 'nano'], g:Editors)
+ unlet g:Editors
+
" test for using try/catch
%d _
let lines =<< trim END
diff --git a/src/version.c b/src/version.c
index 962fa0ba1..169468b0e 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4633,
+/**/
4632,
/**/
4631,