inccommand: Ignore leading modifiers in the command

This commit is contained in:
James McCoy 2017-10-23 19:52:23 -04:00
parent e35a66d396
commit f1f7f3b512
No known key found for this signature in database
GPG Key ID: DFE691AE331BA3DB
2 changed files with 45 additions and 1 deletions

View File

@ -9883,7 +9883,7 @@ static void ex_terminal(exarg_T *eap)
/// Checks if `cmd` is "previewable" (i.e. supported by 'inccommand'). /// Checks if `cmd` is "previewable" (i.e. supported by 'inccommand').
/// ///
/// @param[in] cmd Commandline to check. May start with a range. /// @param[in] cmd Commandline to check. May start with a range or modifier.
/// ///
/// @return true if `cmd` is previewable /// @return true if `cmd` is previewable
bool cmd_can_preview(char_u *cmd) bool cmd_can_preview(char_u *cmd)
@ -9892,6 +9892,12 @@ bool cmd_can_preview(char_u *cmd)
return false; return false;
} }
// Ignore any leading modifiers (:keeppatterns, :verbose, etc.)
for (int len = modifier_len(cmd); len != 0; len = modifier_len(cmd)) {
cmd += len;
cmd = skipwhite(cmd);
}
exarg_T ea; exarg_T ea;
// parse the command line // parse the command line
ea.cmd = skip_range(cmd, NULL); ea.cmd = skip_range(cmd, NULL);

View File

@ -701,6 +701,25 @@ describe(":substitute, inccommand=split", function()
eq(0, eval("&modified")) eq(0, eval("&modified"))
end) end)
it("shows preview when cmd modifiers are present", function()
-- one modifier
feed(':keeppatterns %s/tw/to')
screen:expect([[too lines]], nil, nil, nil, true)
feed('<Esc>')
screen:expect([[two lines]], nil, nil, nil, true)
-- multiple modifiers
feed(':keeppatterns silent %s/tw/to')
screen:expect([[too lines]], nil, nil, nil, true)
feed('<Esc>')
screen:expect([[two lines]], nil, nil, nil, true)
-- non-modifier prefix
feed(':silent tabedit %s/tw/to')
screen:expect([[two lines]], nil, nil, nil, true)
feed('<Esc>')
end)
it('shows split window when typing the pattern', function() it('shows split window when typing the pattern', function()
feed(":%s/tw") feed(":%s/tw")
screen:expect([[ screen:expect([[
@ -1140,6 +1159,25 @@ describe("inccommand=nosplit", function()
]]) ]])
end) end)
it("shows preview when cmd modifiers are present", function()
-- one modifier
feed(':keeppatterns %s/tw/to')
screen:expect([[too lines]], nil, nil, nil, true)
feed('<Esc>')
screen:expect([[two lines]], nil, nil, nil, true)
-- multiple modifiers
feed(':keeppatterns silent %s/tw/to')
screen:expect([[too lines]], nil, nil, nil, true)
feed('<Esc>')
screen:expect([[two lines]], nil, nil, nil, true)
-- non-modifier prefix
feed(':silent tabedit %s/tw/to')
screen:expect([[two lines]], nil, nil, nil, true)
feed('<Esc>')
end)
it('never shows preview buffer', function() it('never shows preview buffer', function()
feed_command("set hlsearch") feed_command("set hlsearch")