commit 5977bdba05666b60bd954dc4400447e8ecd8e412
parent b2828af5b5aba044cd40594a519d2d9f5dbb69cb
Author: zeertzjq <zeertzjq@outlook.com>
Date: Sat, 9 Aug 2025 09:16:13 +0800
fix(cmdline): trigger CmdlineChanged after command preview (#35254)
Diffstat:
2 files changed, 54 insertions(+), 23 deletions(-)
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
@@ -2793,15 +2793,6 @@ static void do_autocmd_cmdlinechanged(int firstc)
static int command_line_changed(CommandLineState *s)
{
- if (ccline.cmdpos != s->prev_cmdpos
- || (s->prev_cmdbuff != NULL
- && strncmp(s->prev_cmdbuff, ccline.cmdbuff, (size_t)s->prev_cmdpos) != 0)) {
- // Trigger CmdlineChanged autocommands.
- do_autocmd_cmdlinechanged(s->firstc > 0 ? s->firstc : '-');
- }
-
- may_trigger_cursormovedc(s);
-
const bool prev_cmdpreview = cmdpreview;
if (s->firstc == ':'
&& current_sctx.sc_sid == 0 // only if interactive
@@ -2823,6 +2814,15 @@ static int command_line_changed(CommandLineState *s)
}
}
+ if (ccline.cmdpos != s->prev_cmdpos
+ || (s->prev_cmdbuff != NULL
+ && strncmp(s->prev_cmdbuff, ccline.cmdbuff, (size_t)s->prev_cmdpos) != 0)) {
+ // Trigger CmdlineChanged autocommands.
+ do_autocmd_cmdlinechanged(s->firstc > 0 ? s->firstc : '-');
+ }
+
+ may_trigger_cursormovedc(s);
+
if (p_arshape && !p_tbidi) {
// Always redraw the whole command line to fix shaping and
// right-left typing. Not efficient, but it works.
diff --git a/test/functional/ui/inccommand_user_spec.lua b/test/functional/ui/inccommand_user_spec.lua
@@ -569,20 +569,51 @@ describe("'inccommand' for user commands", function()
assert(screen._cursor.col < 12)
end
feed(':Test baz<Left><Left>arb')
- screen:expect({
- grid = [[
- Preview |
- oh no, even more text |
- will the text ever stop |
- oh well |
- did the text stop |
- why won't it stop |
- make the text stop |
- |
- {1:~ }|*8
- :Test barb^az |
- ]],
- })
+ screen:expect([[
+ Preview |
+ oh no, even more text |
+ will the text ever stop |
+ oh well |
+ did the text stop |
+ why won't it stop |
+ make the text stop |
+ |
+ {1:~ }|*8
+ :Test barb^az |
+ ]])
+ end)
+
+ it('works when CmdlineChanged calls wildtrigger() #35246', function()
+ api.nvim_buf_set_text(0, 0, 0, 1, -1, { '' })
+ exec_lua([[
+ vim.api.nvim_create_user_command("Repro", function() end, {
+ nargs = '+',
+ preview = function(opts, ns, buf)
+ vim.api.nvim_buf_set_lines(0, 0, -1, true, { opts.args })
+ return 2
+ end
+ })
+ ]])
+ command([[autocmd CmdlineChanged [:/\?] call wildtrigger()]])
+ command('set wildmode=noselect:lastused,full wildoptions=pum')
+ feed(':Repro ')
+ screen:expect([[
+ |
+ {1:~ }|*15
+ :Repro ^ |
+ ]])
+ feed('a')
+ screen:expect([[
+ a |
+ {1:~ }|*15
+ :Repro a^ |
+ ]])
+ feed('bc')
+ screen:expect([[
+ abc |
+ {1:~ }|*15
+ :Repro abc^ |
+ ]])
end)
end)